blob: a9c71b7ac6a05f43b689344511c8e9b9c408c854 [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001======================================
2Internal Trusted Storage (ITS) Service
3======================================
Jamie Fox69257652019-07-03 17:53:13 +01004
5:Author: Jamie Fox
6:Organization: Arm Limited
7:Contact: Jamie Fox <jamie.fox@arm.com>
8:Status: Accepted
9
10PSA Internal Trusted Storage
11============================
12PSA Internal Trusted Storage (ITS) is a PSA RoT Service for storing the most
13security-critical device data (e.g. cryptographic keys) in internal storage,
14which is trusted to provide data confidentiality and authenticity. This
15contrasts with PSA Protected Storage, which is an Application RoT service that
16allows larger data sets to be stored securely in external flash, with the option
17for encryption, authentication and rollback protection to protect the
18data-at-rest.
19
20Current TF-M Secure Storage
21===========================
22Currently, the TF-M Secure Storage service implements PSA Protected Storage
23version 1.0-beta2. There is not yet an implementation of PSA Internal Trusted
24Storage in TF-M.
25
26New TF-M service
27================
28The proposal is to implement the *PSA Internal Trusted Storage API* with the
29*TF-M Internal Trusted Storage service*. It can be abbreviated to *TF-M ITS
30service* in general and to ``its`` in code. This name has the advantage of
31making clear the correspondence between the service and the API it implements.
32
33If this name is adopted, then it may make sense to rename the *Secure Storage
34service* to the *Protected Storage service* in the future to match. Then "secure
35storage" could refer to the two services as a collective.
36
37The TF-M ITS service will implement PSA ITS version 1.0. It will be provided by
38a separate partition to Protected Storage, for a couple of reasons:
39
40- To permit isolation between the services.
41
42 - ITS is a PSA RoT Service, while Protected Storage is an Application RoT
43 Service.
44
45- To avoid circular dependencies.
46
47 - The PSA Firmware Framework does not permit circular dependencies between
48 partitions, which would occur if Protected Storage and ITS were provided by
49 the same partition. Protected Storage depends on Crypto, which in turn
50 depends on ITS.
51
52The existing SST filesystem will be reused to provide the backend of the
53service, with the flash layer modified to direct storage to internal flash,
54rather than external.
55
56Compared to Protected Storage, encryption, authentication and rollback
57protection are not required, so the SST encrypted object layer and the crypto
58and NV counter interfaces are not required. The rollback protection feature of
59the object table is also not required.
60
61Code structure
62==============
63The code structure of the service will be as follows:
64
Kevin Peng1a2f3652020-07-30 15:17:05 +080065TF-M repo:
66
Jamie Fox69257652019-07-03 17:53:13 +010067``interface/``
68
69- ``include/psa/internal_trusted_storage.h`` - PSA ITS API
70- ``src/tfm_its_api.c`` - PSA ITS API implementation for NSPE
71
72``secure_fw/ns_callable/tfm_veneers.c`` - ITS veneers (auto-generated from
73manifest)
74
Ken Liu738a4b02020-06-04 14:52:38 +080075``secure_fw/partitions/internal_trusted_storage/``
Jamie Fox69257652019-07-03 17:53:13 +010076
77- ``tfm_internal_trusted_storage.yaml`` - Partition manifest
78- ``tfm_its_secure_api.c`` - PSA ITS API implementation for SPE
79- ``tfm_its_req_mngr.c`` - Uniform secure functions and IPC request handlers
80- ``tfm_internal_trusted_storage.h`` - TF-M ITS API (with client_id parameter)
81- ``tfm_internal_trusted_storage.c`` - TF-M ITS implementation, using the
82 flash_fs as a backend
83- ``flash_fs/`` - Filesystem
84- ``flash/`` - Flash interface
85
Kevin Peng1a2f3652020-07-30 15:17:05 +080086tf-m-tests repo:
87
Jamie Fox69257652019-07-03 17:53:13 +010088``test/suites/its/``
89
90- ``non_secure/psa_its_ns_interface_testsuite.c`` - Non-secure interface tests
91- ``secure/psa_its_s_interface_testsuite.c`` - Secure interface tests
92
93TF-M ITS implementation
94-----------------------
95The following APIs will be exposed by ``tfm_internal_trusted_storage.h``::
96
97 psa_status_t tfm_its_init(void);
98
99 psa_status_t tfm_its_set(int32_t client_id,
100 psa_storage_uid_t uid,
101 size_t data_length,
102 const void *p_data,
103 psa_storage_create_flags_t create_flags);
104
105 psa_status_t tfm_its_get(int32_t client_id,
106 psa_storage_uid_t uid,
107 size_t data_offset,
108 size_t data_size,
109 void *p_data,
110 size_t *p_data_length);
111
112 psa_status_t tfm_its_get_info(int32_t client_id,
113 psa_storage_uid_t uid,
114 struct psa_storage_info_t *p_info);
115
116 psa_status_t tfm_its_remove(int32_t client_id,
117 psa_storage_uid_t uid);
118
119That is, the TF-M ITS APIs will have the same prototypes as the PSA ITS APIs,
120but with the addition of a ``client_id`` parameter, which will be passed from
121the ITS request manager. A ``tfm_its_init`` function will also be present, which
122will be called at initialisation time and not exposed through a veneer or SID.
123
124The implementation in ``tfm_internal_trusted_storage.c`` must validate the
125parameters (excepting memory references, which are validated by the SPM),
126translate the UID and client ID into a file ID and then make appropriate calls
127to the filesystem layer. It must also take care ensure that any PSA Storage
128flags associated with the UID are honoured.
129
130Filesystem
131----------
132The ITS filesystem will be copied and modified from the SST filesystem. The
133modifications required will be to rename symbols from ``sst`` to ``its`` and to
134update the implementation to be aligned with the latest version of the PSA
135Storage spec (which consists mainly of moving to the ``psa_status_t`` error type
136and using common error codes from ``psa/error.h``).
137
138The filesystem will also be modified to align the size of each file stored to
139the alignment requirement exposed by the flash interface, by adding appropriate
140padding.
141
142The filesystem code will be de-duplicated again once the ITS service is
143implemented (see below).
144
145Flash layer
146-----------
147The flash layer will be copied from SST, and modified to direct writes to the
148internal flash device. It too needs to be updated to use ``psa_status_t`` error
149types.
150
151Platform layer
152--------------
153The TF-M platform layer must be be updated to distinguish between the external
154flash device used for Protected Storage and internal flash device used for ITS.
155A flash region for the relevant storage service needs to be allocated in each.
156
157On test platforms these may just be two distinct regions of the same flash
158device, but in general they will separate devices with their own drivers.
159
160Detailed design considerations
161==============================
162
163Mapping UID onto file ID
164------------------------
165The ITS APIs identify assets with 64-bit UIDs, to which the ITS service must
166append the 32-bit client ID of the calling partition for access control. The
167existing filesystem uses 32-bit file IDs to identify files, so some mapping
168would be required to convert between the identifiers.
169
170SST uses the object table to do the mapping from client ID, UID pairs to file
171IDs, which means making an extra filesystem read/write for each get/set
172operation. This mapping has minimal overhead for SST though, because object
173table lookups are already required for rollback protection.
174
175For ITS, no rollback protection feature is required, so there are two options:
176
177- Keep a simplified version of the SST object table that just maps from
178 (client ID, UID) to file ID
179
180- Modify the filesystem to take (at least) 96-bit file IDs, in the form of a
181 fixed-length char buffer.
182
183The advantage of the former is that it would require no extra modification to
184the existing filesystem code, and the existing SST object table could be cut
185down for ITS. However, it would mean that every ITS request would invoke twice
186the number of filesystem operations, increasing latency and flash wear. The code
187size of the ITS partition would be increased, as would RAM usage as the table
188would need to be read into RAM.
189
190The latter option would make the filesystem slightly more complex: the size of a
191metadata entry would be increased by 64-bits and the 96-bit fids would need to
192be copied and compared with ``memcpy`` and ``memcmp`` calls. On the other hand,
193mapping onto file IDs would incur only the cost of copying the UID and client ID
194values into the file ID buffer.
195
196A third, even more general, solution would be to use arbitrary-length
197null-terminated strings as the file IDs. This is the standard solution in
198full-featured filesystems, but we do not currently require this level of
199complexity in secure storage.
200
201With this in mind, the proposed option is the second.
202
203Storing create flags
204--------------------
205The ITS APIs provide a 32-bit ``create_flags`` parameter, which contains bit
206flags that determine the properties of the stored data. Only one flag is
207currently defined for ITS: ``PSA_STORAGE_FLAG_WRITE_ONCE``, which prevents a UID
208from being modified or deleted after it is set for the first time.
209
210There are two places that these flags could be stored: in the file data or as
211part of the file metadata.
212
213For the first option, the ITS implementation would need to copy to the flags
214into the buffer containing the data, and adjust the size accordingly, for each
215set operation, and the reverse for each get. Every get_info operation would need
216to read some of the file data, rather than just the metadata, implying a second
217flash read. A potential downside is that many of the cryptographic assets stored
218in ITS will be aligned to power-of-two sizes; adding an extra 32-bits would
219misalign the size, which may reduce flash performance or necessitate adding
220padding to align to the flash page size.
221
222To implement the second option, a 32-bit ``flag`` field would be added to the
223filesystem's metadata structure, whose interpretation is defined by the user.
224This field would clearly be catered towards the PSA Storage APIs, even if
225nominally generic, and alternative filesystems may not have any such field.
226However, it is a more intuitive solution and would simplify both flash alignment
227and get_info operations.
228
229Overall, it seems more beneficial to store the flags in the metadata, so this is
230the proposed solution.
231
232Code sharing between Protected Storage and ITS
233----------------------------------------------
234To de-duplicate the filesystem code used by both Protected Storage and ITS, it
235is proposed that Protected Storage calls ITS APIs as its backend filesystem.
236
237Protected Storage essentially becomes an encryption, authentication and rollback
238protection layer on top of ITS. It makes IPC requests or secure function calls
239to the ITS service to do filesystem operations on its behalf.
240
241This has a couple of advantages:
242
243- It shrinks Protected Storage's stack size, because the filesystem and flash
244 layer stack is only in ITS.
245
246- It automatically solves the problem of ensuring mutual exclusion in the
247 filesystem and flash layers when Protected Storage and ITS are called
248 concurrently. The second request to ITS will just be made to wait by the SPM.
249
250The disadvantage of this approach is that it will increase the latency of
251Protected Storage requests, due to the extra overhead associated with making a
252second IPC request or secure function call. It also limits Protected Storage to
253using only the ITS APIs, unless extra veneers are added solely for Protected
254Storage to use. This, for example, prevents Protected Storage from doing partial
255writes to file without reading and re-writing the whole file.
256
257ITS will need to be modified to direct calls from Protected Storage to a
258different flash device. It can use the client ID to detect when the caller is
259Protected Storage, and pass down the identity of the flash device to use to the
260flash layer, which then calls the appropriate driver.
261
262An open question is what to do if Protected Storage itself wants to store
263something in internal storage in the future (e.g. rollback counters, hash
264tree/table or top hash). A couple of possible solutions would be:
265
266- Divide up the UIDs, so certain UIDs from Protected Storage refer to assets in
267 internal storage, and others to ones in external storage.
268
269- Use the ``type`` field of ``psa_call`` in IPC model and extra veneers in
270 library model to distinguish between internal and external storage requests.
271
272The other option for code sharing would be for Protected Storage and ITS to
273directly share filesystem code, which would be placed in a shared code region.
274With this approach, mutual exclusion to the flash device would need to be
275implemented separately, as would some way of isolating static memory belonging
276to each partition but not the code. Because of these complications, this option
277has not been considered further at this time.
278
279--------------
280
281*Copyright (c) 2019, Arm Limited. All rights reserved.*