Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 1 | .. _trusted_applications: |
| 2 | |
| 3 | #################### |
| 4 | Trusted Applications |
| 5 | #################### |
| 6 | There are two ways to implement Trusted Applications (TAs), Pseudo TAs and user |
| 7 | mode TAs. User mode TAs are full featured Trusted Applications as specified by |
| 8 | the :ref:`globalplatform_api` TEE specifications, these are simply the ones |
| 9 | people are referring to when they are saying "Trusted Applications" and in most |
| 10 | cases this is the preferred type of TA to write and use. |
| 11 | |
| 12 | .. _pta: |
| 13 | |
| 14 | Pseudo Trusted Applications |
| 15 | *************************** |
| 16 | These are implemented directly to the OP-TEE core tree in, e.g., |
Jerome Forissier | fa993db | 2019-09-13 15:58:53 +0200 | [diff] [blame] | 17 | ``core/pta`` and are built along with and statically built into the |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 18 | OP-TEE core blob. |
| 19 | |
| 20 | The Pseudo Trusted Applications included in OP-TEE already are OP-TEE secure |
| 21 | privileged level services hidden behind a "GlobalPlatform TA Client" API. These |
| 22 | Pseudo TAs are used for various purposes such as specific secure services or |
| 23 | embedded tests services. |
| 24 | |
| 25 | Pseudo TAs **do not** benefit from the GlobalPlatform Core Internal API support |
| 26 | specified by the GlobalPlatform TEE specs. These APIs are provided to TAs as a |
| 27 | static library each TA shall link against (the ":ref:`libutee`") and that calls |
| 28 | OP-TEE core service through system calls. As OP-TEE core does not link with |
| 29 | :ref:`libutee`, Pseudo TAs can **only** use the OP-TEE core internal APIs and |
| 30 | routines. |
| 31 | |
| 32 | As Pseudo TAs runs at the same privileged execution level as the OP-TEE core |
| 33 | code itself and that might or might not be desirable depending on the use case. |
| 34 | |
| 35 | In most cases an unprivileged (user mode) TA is the best choice instead of |
| 36 | adding your code directly to the OP-TEE core. However if you decide your |
| 37 | application is best handled directly in OP-TEE core like this, you can look at |
Jerome Forissier | fa993db | 2019-09-13 15:58:53 +0200 | [diff] [blame] | 38 | ``core/pta/stats.c`` as a template and just add your Pseudo TA based on |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 39 | that to the ``sub.mk`` in the same directory. |
| 40 | |
| 41 | .. _user_mode_ta: |
| 42 | |
| 43 | User Mode Trusted Applications |
| 44 | ****************************** |
| 45 | User Mode Trusted Applications are loaded (mapped into memory) by OP-TEE core in |
| 46 | the Secure World when something in Rich Execution Environment (REE) wants to |
| 47 | talk to that particular application UUID. They run at a lower CPU privilege |
| 48 | level than OP-TEE core code. In that respect, they are quite similar to regular |
| 49 | applications running in the REE, except that they execute in Secure World. |
| 50 | |
| 51 | Trusted Application benefit from the GlobalPlatform :ref:`tee_internal_core_api` |
| 52 | as specified by the GlobalPlatform TEE specifications. There are several types |
| 53 | of user mode TAs, which differ by the way they are stored. |
| 54 | |
| 55 | TA locations |
| 56 | ************ |
| 57 | Plain TAs (user mode) can reside and be loaded from various places. There are |
| 58 | three ways currently supported in OP-TEE. |
| 59 | |
| 60 | .. _early_ta: |
| 61 | |
| 62 | Early TA |
| 63 | ======== |
| 64 | The so-called early TAs are virtually identical to the REE FS TAs, but instead |
| 65 | of being loaded from the Normal World file system, they are linked into a |
| 66 | special data section in the TEE core blob. Therefore, they are available even |
| 67 | before ``tee-supplicant`` and the REE's filesystems have come up. Please find |
| 68 | more details in the `early TA commit`_. |
| 69 | |
| 70 | .. _ree_fs_ta: |
| 71 | |
| 72 | REE filesystem TA |
| 73 | ================= |
| 74 | They consist of a cleartext signed ELF_ file, named from the UUID of the TA and |
| 75 | the suffix ``.ta``. They are built separately from the OP-TEE core boot-time |
| 76 | blob, although when they are built they use the same build system, and are |
| 77 | signed with the key from the build of the original OP-TEE core blob. |
| 78 | |
| 79 | Because the TAs are signed, they are able to be stored in the untrusted REE |
| 80 | filesystem, and ``tee-supplicant`` will take care of passing them to be checked |
| 81 | and loaded by the Secure World OP-TEE core. Note that this type of TA isn't |
| 82 | encrypted. |
| 83 | |
| 84 | .. _secure_storage_ta: |
| 85 | |
| 86 | Secure Storage TA |
| 87 | ================= |
| 88 | These are stored in secure storage. The meta data is stored in a database of all |
| 89 | installed TAs and the actual binary is stored encrypted and integrity protected |
| 90 | as a separate file in the untrusted REE filesystem (flash). Before these TAs can |
| 91 | be loaded they have to be installed first, this is something that can be done |
| 92 | during initial deployment or at a later stage. |
| 93 | |
| 94 | For test purposes the test program xtest can install a TA into secure storage |
| 95 | with the command: |
| 96 | |
| 97 | .. code-block:: bash |
| 98 | |
| 99 | $ xtest --install-ta |
| 100 | |
| 101 | |
| 102 | .. _ta_properties: |
| 103 | |
| 104 | TA Properties |
| 105 | ************* |
| 106 | This section give a more in depth description of the TA properties (see |
| 107 | :ref:`build_trusted_applications` also). |
| 108 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 109 | GlobalPlatform Properties |
| 110 | ========================= |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 111 | Standard TA properties must be defined through property flag in macro |
| 112 | ``TA_FLAGS`` in ``user_ta_header_defines.h`` |
| 113 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 114 | Single Instance |
| 115 | --------------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 116 | ``"gpd.ta.singleInstance"`` is a boolean property of the TA. This property |
| 117 | defines if one instance of the TA must be created and will receive all open |
| 118 | session request, or if a new specific TA instance must be created for each |
| 119 | incoming open session request. OP-TEE TA flag ``TA_FLAG_SINGLE_INSTANCE`` sets |
| 120 | to configuration of this property. The boolean property is set to ``true`` if |
| 121 | ``TA_FLAGS`` sets bit ``TA_FLAG_SINGLE_INSTANCE``, otherwise the boolean |
| 122 | property is set to ``false``. |
| 123 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 124 | Multi-session |
| 125 | ------------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 126 | ``"gpd.ta.multiSession"`` is a boolean property of the TA. This property defines |
| 127 | if the TA instance can handle several sessions. If disabled, TA instance support |
| 128 | only one session. In such case, if the TA already has a opened session, any open |
| 129 | session request will return with a busy error status. |
| 130 | |
| 131 | .. note:: |
| 132 | |
| 133 | This property is **meaningless** if TA is **NOT** SingleInstance TA. |
| 134 | |
| 135 | OP-TEE TA flag ``TA_FLAG_MULTI_SESSION`` sets to configuration of this property. |
| 136 | The boolean property is set to ``true`` if ``TA_FLAGS`` sets bit |
| 137 | ``TA_FLAG_MULTI_SESSION``, otherwise the boolean property is set to ``false``. |
| 138 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 139 | Keep Alive |
| 140 | ---------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 141 | ``"gpd.ta.instanceKeepAlive"`` is a boolean property of the TA. This property |
| 142 | defines if the TA instance created must be destroyed or not when all sessions |
| 143 | opened towards the TA are closed. If the property is enabled, TA instance, once |
| 144 | created (at 1st open session request), is never removed unless the TEE itself is |
| 145 | restarted (boot/reboot). |
| 146 | |
| 147 | .. note:: |
| 148 | |
| 149 | This property is **meaningless** if TA is **NOT** SingleInstance TA. |
| 150 | |
| 151 | OP-TEE TA flag ``TA_FLAG_INSTANCE_KEEP_ALIVE`` sets to configuration of this |
| 152 | property. The boolean property is set to ``true`` if ``TA_FLAGS`` sets bit |
| 153 | ``TA_FLAG_INSTANCE_KEEP_ALIVE``, otherwise the boolean property is set to |
| 154 | ``false``. |
| 155 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 156 | Heap Size |
| 157 | --------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 158 | ``"gpd.ta.dataSize"`` is a 32bit integer property of the TA. This property |
| 159 | defines the size in bytes of the TA allocation pool, in which ``TEE_Malloc()`` |
| 160 | and friends allocate memory. The value of the property must be defined by the |
| 161 | macro ``TA_DATA_SIZE`` in ``user_ta_header_defines.h`` (see |
| 162 | :ref:`build_ta_properties`). |
| 163 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 164 | Stack Size |
| 165 | ---------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 166 | ``"gpd.ta.stackSize"`` is a 32bit integer property of the TA. This property |
| 167 | defines the size in bytes of the stack used for TA execution. The value of the |
| 168 | property must be defined by the macro ``TA_STACK_SIZE`` in |
| 169 | ``user_ta_header_defines.h`` (see :ref:`build_ta_properties`). |
| 170 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 171 | Property Extensions |
| 172 | =================== |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 173 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 174 | Secure Data Path Flag |
| 175 | --------------------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 176 | ``TA_FLAG_SECURE_DATA_PATH`` is a bit flag supported by ``TA_FLAGS``. This |
| 177 | property flag claims the secure data support from the OP-TEE OS for the TA. |
| 178 | Refer to the OP-TEE OS for secure data path support. TAs that do not set |
| 179 | ``TA_FLAG_SECURE_DATA_PATH`` in the value of ``TA_FLAGS`` will **not** be able |
| 180 | to handle memory reference invocation parameters that relate to secure data path |
| 181 | buffers. |
| 182 | |
Etienne Carriere | 5b99ccc | 2019-03-11 11:57:30 +0100 | [diff] [blame] | 183 | .. _ta_property_cache_maintenance: |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 184 | |
| 185 | Cache maintenance Flag |
| 186 | ---------------------- |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 187 | ``TA_FLAG_CACHE_MAINTENANCE`` is a bit flag supported by ``TA_FLAGS``. This |
Etienne Carriere | 5b99ccc | 2019-03-11 11:57:30 +0100 | [diff] [blame] | 188 | property flag, when enabled, allows Trusted Applciation to use the cache |
| 189 | maintenance API extension of the Internal Core API described in |
| 190 | :ref:`extensions_cache_maintenance`. TAs that do not set |
| 191 | ``TA_FLAG_CACHE_MAINTENANCE`` in the value of their ``TA_FLAGS`` will not be |
| 192 | able to call the cache maintenance API. |
Etienne Carriere | 0ab5cc2 | 2019-03-11 10:44:13 +0100 | [diff] [blame] | 193 | |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 194 | Deprecated Property Flags |
| 195 | ------------------------- |
Etienne Carriere | 0ab5cc2 | 2019-03-11 10:44:13 +0100 | [diff] [blame] | 196 | Older versions of OP-TEE used to define extended property flags that are |
| 197 | deprecated and meaningless to current OP-TEE. These are ``TA_FLAG_USER_MODE``, |
| 198 | ``TA_FLAG_EXEC_DDR`` and ``TA_FLAG_REMAP_SUPPORT``. |
Etienne Carriere | 2f459d1 | 2019-03-11 11:58:05 +0100 | [diff] [blame] | 199 | |
| 200 | .. _ELF: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format |
| 201 | .. _early TA commit: https://github.com/OP-TEE/optee_os/commit/d0c636148b3a |