Mingyang Sun | 8360ef7 | 2021-01-07 18:02:45 +0800 | [diff] [blame^] | 1 | ########################################## |
| 2 | Stateless Root of Trust Services Reference |
| 3 | ########################################## |
| 4 | |
| 5 | :Author: Mingyang Sun |
| 6 | :Organization: Arm Limited |
| 7 | :Contact: mingyang.sun@arm.com |
| 8 | |
| 9 | |
| 10 | ************ |
| 11 | Introduction |
| 12 | ************ |
| 13 | |
| 14 | This document describes the implementation for the FF-M v1.1 feature - |
| 15 | 'Stateless RoT Service', and the related references when developing RoT |
| 16 | services. |
| 17 | |
| 18 | It is recommended to refer to the FF-M v1.0 specification [1]_ and FF-M v1.1 |
| 19 | extension [2]_ for background and rationale details. |
| 20 | |
| 21 | |
| 22 | ********************** |
| 23 | Implementation Details |
| 24 | ********************** |
| 25 | |
| 26 | This chapter describes the implementation-defined items, including stateless |
| 27 | handle value definition, tooling update, and programming API changes. |
| 28 | |
| 29 | Stateless Handle Value Definition |
| 30 | ================================= |
| 31 | |
| 32 | The index, stateless indicator, and service version information are encoded into |
| 33 | a handle by the manifest tooling, and then generated to header file ``sid.h``. |
| 34 | |
| 35 | .. list-table:: Bit Fields of Stateless Handle |
| 36 | :header-rows: 1 |
| 37 | :widths: 20 80 |
| 38 | |
| 39 | * - Bits |
| 40 | - Field Description |
| 41 | * - bit 31 |
| 42 | - reserved |
| 43 | * - bit 30 |
| 44 | - stateless handle indicator bit, always 1 |
| 45 | * - bit 29 - bit 16 |
| 46 | - reserved |
| 47 | * - bit 15 - bit 8 |
| 48 | - service version requested by client - for client version check |
| 49 | * - bit 7 - bit 0 |
| 50 | - the handle index, [0, 31] |
| 51 | |
| 52 | Since connection-based services and stateless services share the same PSA API |
| 53 | ``psa_call()``, an indicator bit is set in the handle indicate the type of the |
| 54 | handle. If it is set, the handle is stateless, and definition is as described |
| 55 | in the table above. Maximum connection-based handle is 0x3FFFFFFF, thus the |
| 56 | indicator bit is always 0. |
| 57 | |
| 58 | The index is used for organizing stateless services in manifest tool and |
| 59 | locating a stateless service in SPM logic. A range of index [0, 31] is the |
| 60 | initial implementation. Future expansion is possible. |
| 61 | |
| 62 | Tooling Support |
| 63 | =============== |
| 64 | |
| 65 | TF-M provides a tool (``tools/tfm_parse_manifest_list.py``) to generate source |
| 66 | header files required by partition and services. For example, the generated |
| 67 | ``sid.h`` contains service ID and version. The tooling is extended to generate |
| 68 | stateless handle from partition manifests automatically. |
| 69 | |
| 70 | The ``stateless_handle`` attribute in manifest is only supported by partitions |
| 71 | with firmware framework version 1.1. |
| 72 | |
| 73 | - If ``stateless_handle`` in manifest is set to an integer, the index is |
| 74 | ``stateless_handle - 1``. |
| 75 | - If it is ``auto`` or not set, the first empty index in range [0, 31] is |
| 76 | assigned. |
| 77 | - Other settings - tooling reports an error. |
| 78 | |
| 79 | Finally, the tooling encodes the handle according to definitions in |
| 80 | `Stateless Handle Value Definition`_ section, and writes them to ``sid.h`` |
| 81 | header file. |
| 82 | |
| 83 | Changes in Programming API |
| 84 | ========================== |
| 85 | |
| 86 | This chapter describes the changes in programming API for stateless services. |
| 87 | The following APIs' bebavious and message data structure members are updated to |
| 88 | support the stateless service. |
| 89 | |
| 90 | psa_connect() |
| 91 | ------------- |
| 92 | |
| 93 | According to FF-M v1.1, client calling ``psa_connect()`` with the SID of a |
| 94 | stateless RoT Service is a ``PROGRAMMER_ERROR``. |
| 95 | |
| 96 | psa_close() |
| 97 | ----------- |
| 98 | |
| 99 | According to FF-M v1.1, client passing a stateless handle to call this API is a |
| 100 | ``PROGRAMMER_ERROR``. |
| 101 | |
| 102 | psa_call() |
| 103 | ---------- |
| 104 | |
| 105 | .. code-block:: c |
| 106 | |
| 107 | psa_status_t psa_call(psa_handle_t handle, int32_t type, |
| 108 | const psa_invec *in_vec, size_t in_len, |
| 109 | psa_outvec *out_vec, size_t out_len) |
| 110 | |
| 111 | API parameters and behaviour change: |
| 112 | |
| 113 | 1. The ``handle`` parameter must be a stateless handle defined in |
| 114 | ``psa_manifest/sid.h`` when requesting a stateless service. |
| 115 | 2. This API validates stateless handle, decodes index and service version |
| 116 | information from it. SPM uses the index to know which stateless service is |
| 117 | requested. |
| 118 | 3. This API performs some operations as ``psa_connect()`` does, such as the |
| 119 | authorization check, service and client version check, and handle space |
| 120 | allocation. |
| 121 | |
| 122 | Service behaviour change during a "psa_call": |
| 123 | |
| 124 | Service does not accept connection and disconnection messages. After a |
| 125 | "psa_call" request is serviced, it calls ``psa_reply()``, frees the connection |
| 126 | handle to handle pool. |
| 127 | |
| 128 | psa_set_rhandle() |
| 129 | ----------------- |
| 130 | |
| 131 | According to FF-M v1.1, stateless service calling this API on a message is a |
| 132 | ``PROGRAMMER_ERROR`` and it will never return. |
| 133 | |
| 134 | psa_msg_t type |
| 135 | -------------- |
| 136 | |
| 137 | The ``rhandle`` member of a ``psa_msg_t`` type received by a stateless RoT |
| 138 | Service is always ``NULL``. |
| 139 | |
| 140 | |
| 141 | ************************** |
| 142 | Application Recommendation |
| 143 | ************************** |
| 144 | |
| 145 | There are particular services that do not need sessions. The access to the |
| 146 | service is a one-shot connection. These services provide standalone operations |
| 147 | that do not require any non-volatile state of resources to be maintained by the |
| 148 | RoT service itself or do not expose any kind of context or session to the |
| 149 | caller. Such services are recommended to be implemented as stateless, to provide |
| 150 | quick access and to avoid extra overheads. |
| 151 | |
| 152 | In this case, ``rhandle`` access would be prohibited as it is used for saving |
| 153 | state or non-volatile resources while stateless services do not need them. |
| 154 | |
| 155 | Update Feasibility of Existing Services |
| 156 | ======================================= |
| 157 | |
| 158 | TF-M native services are used widely. They only need standalone operations and |
| 159 | do not need to keep state between sessions. For example, the service in Crypto |
| 160 | partition does not do anything during ``psa_connect()`` or ``psa_close()`` |
| 161 | process. Same for services in other partitions, thus all of them can be |
| 162 | implemented as stateless. |
| 163 | |
| 164 | Analysis for them: |
| 165 | |
| 166 | .. list-table:: TF-M Partition Services Update Possibility |
| 167 | :header-rows: 1 |
| 168 | :widths: 30 30 40 |
| 169 | |
| 170 | * - Partition |
| 171 | - Number of Services |
| 172 | - Can be Stateless |
| 173 | * - ITS |
| 174 | - 4 |
| 175 | - All |
| 176 | * - PS |
| 177 | - 5 |
| 178 | - All |
| 179 | * - Crypto |
| 180 | - 1 |
| 181 | - All |
| 182 | * - FWU |
| 183 | - 6 |
| 184 | - All |
| 185 | * - Platform |
| 186 | - 4 |
| 187 | - All |
| 188 | * - Initial Attestation |
| 189 | - 2 |
| 190 | - All |
| 191 | |
| 192 | Other services are not analyzed here. |
| 193 | |
| 194 | Grouping Services |
| 195 | ================= |
| 196 | |
| 197 | Stateless service table is stored statically, and TF-M supports 32 stateless |
| 198 | services currently. |
| 199 | |
| 200 | Similar stateless services in a partition could be grouped, and assign one |
| 201 | ``SID`` for the group. The ``type`` parameter in ``psa_call()`` could be |
| 202 | extended to identify the service in group. In this case, it is recommended to |
| 203 | use consecutive value for ``type``. |
| 204 | |
| 205 | It is recommended that each Seccure Partition declares one stateless service |
| 206 | and uses the type parameter to distinguish different stateless services. |
| 207 | Therefore, more stateless services can be supported. |
| 208 | |
| 209 | Migrating to Stateless Services |
| 210 | =============================== |
| 211 | |
| 212 | Please refer to Chapter 4 "Stateless Root of Trust services", Appendix B.3.2 |
| 213 | "Using a stateless RoT Service", and Appendix D "Implementing session-less RoT |
| 214 | Services" in FF-M v1.1 document for details on which kind of service can be |
| 215 | stateless and how to implement a stateless service. |
| 216 | |
| 217 | |
| 218 | ********* |
| 219 | Reference |
| 220 | ********* |
| 221 | |
| 222 | .. [1] `FF-M v1.0 Specification <https://developer.arm.com/-/media/Files/pdf/PlatformSecurityArchitecture/Architect/DEN0063-PSA_Firmware_Framework-1.0.0-2.pdf?revision=2d1429fa-4b5b-461a-a60e-4ef3d8f7f4b4>`__ |
| 223 | |
| 224 | .. [2] `FF-M v1.1 Extention <https://documentation-service.arm.com/static/600067c09b9c2d1bb22cd1c5?token=>`__ |
| 225 | |
| 226 | -------------- |
| 227 | |
| 228 | *Copyright (c) 2021, Arm Limited. All rights reserved.* |