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