blob: b9727cb9f21937719a50453ccd1f9f6f0e5d7184 [file] [log] [blame]
Ken Liu87b4f412020-06-04 11:13:39 +08001##############
2FF-M Isolation
3##############
4
5:Organization: Arm Limited
6:Contact: tf-m@lists.trustedfirmware.org
7
Jamie Fox66677052024-09-10 14:51:48 +01008This document analyzes the isolation rules of implementing Firmware Framework
9for M 1.1 (FF-M 1.1) [2]_ isolation and introduces the reference implementation
10in TF-M, which complies with the rules by operating the hardware and software
11resources.
Ken Liu87b4f412020-06-04 11:13:39 +080012
13.. note::
Anton Komlev3356ba32022-03-31 22:02:11 +010014 Reference the document :doc:`Glossary </glossary>` for terms
Ken Liu87b4f412020-06-04 11:13:39 +080015 and abbreviations.
16
17************
18Introduction
19************
Jamie Fox66677052024-09-10 14:51:48 +010020This chapter describes the definitions from Firmware Framework for M (FF-M) [1]_
21and analyzes the possible implementation keypoints.
Ken Liu87b4f412020-06-04 11:13:39 +080022
23Isolation Levels
24================
Jamie Fox66677052024-09-10 14:51:48 +010025There are 3 isolation levels (1-3) defined in FF-M, the greater level number has
26more isolation boundaries.
Ken Liu87b4f412020-06-04 11:13:39 +080027
28The definition for Isolation Level 1:
29
30- L1.1 NPSE needs protection from nobody.
31- L1.2 SPE needs protection from NSPE.
32
33The definition for Isolation Level 2:
34
35- L2.1 NPSE needs protection from nobody.
36- L2.2 Application Root of Trust (ARoT) needs protection from NSPE.
37- L2.3 PSA Root of Trust (PRoT) needs protection from NSPE and ARoT.
38
39The definition for Isolation Level 3:
40
41- L3.1 NPSE needs protection from nobody.
42- L3.2 Secure Partition needs protection from NSPE and other Secure Partitions.
43- L3.3 PSA Root of Trust (RoT) domain needs protection from NSPE and all Secure
44 Partitions.
45
46.. important::
Ken Liue6b477c2022-08-22 10:56:24 +080047 A Secure Partition RoT Service is a Root of Trust Service implemented within
48 a Secure Partition. An Application RoT Service must be implemented as
49 a Secure Partition RoT Service. But it is implementation-defined whether a
50 PSA RoT Service is a Secure Partition RoT Service.
51
52 Here listed several possible PSA RoT Service implementation mechanisms:
53
Ken Liu0ca70e02023-01-29 17:36:18 +080054 1. Implement PSA RoT Services in Secure Partitions with respective
55 boundaries.
56 2. Implement PSA RoT Services in Secure Partitions, but no boundaries between
57 these Secure Partitions as they are in the PSA RoT Domain.
58 3. Implement PSA RoT Services in a customized way instead of Secure
59 Partitions, an internal library of PSA RoT domain e.g.
Ken Liue6b477c2022-08-22 10:56:24 +080060
61 TF-M chooses the 2nd option to balance performance and complexity.
Ken Liu87b4f412020-06-04 11:13:39 +080062
63Isolation Rules
64===============
65The essence of isolation is to protect the assets of one protection domain from
66being accessed from other domains. The isolation levels define where the
67isolation boundaries should be placed, the isolation rules define the strength
68of the isolation the boundaries should offer.
69
70.. note::
Jamie Fox66677052024-09-10 14:51:48 +010071 Refer to chapter *Memory Assets* in FF-M [1]_ to know asset class items.
72 Assets are represented by memory addresses in the system memory map, which
73 makes assets named *Memory Assets*. The often-seen asset items are ROM, RAM,
74 and memory-mapped peripherals.
Ken Liu87b4f412020-06-04 11:13:39 +080075
76Memory Asset Class
77------------------
Jamie Fox66677052024-09-10 14:51:48 +010078There are 3 memory asset classes defined in FF-M:
Ken Liu87b4f412020-06-04 11:13:39 +080079
80- Code
81- Constant data
82- Private data
83
Jamie Fox66677052024-09-10 14:51:48 +010084There are 7 isolation rules for protecting assets described in chapter ``3.1``
85of FF-M 1.0 [1]_ and chapters ``8.4`` to ``8.5`` of FF-M 1.1 [2]_. The following
86is a summary of the rules:
Ken Liu87b4f412020-06-04 11:13:39 +080087
Jamie Fox66677052024-09-10 14:51:48 +010088- I1. (Changed in FF-M 1.1) Private data is not executable.
Ken Liu87b4f412020-06-04 11:13:39 +080089- I2. Only private data is writable.
90- I3. If domain A needs protection from domain B, then Private data in domain A
91 cannot be accessed by domain B.
Jamie Fox66677052024-09-10 14:51:48 +010092- I4. (Optional, changed in FF-M 1.1) If domain A needs protection from domain
93 B, then Code and Constant data in domain A, which is not part of a shared
94 library, is not readable or executable by domain B.
95- I5. (Optional, changed in FF-M 1.1) Code in a domain, which is not part of a
96 shared library, is not executable by any other domain.
Ken Liu87b4f412020-06-04 11:13:39 +080097- I6. (Optional) All assets in a domain are private to that domain and cannot be
98 accessed by any other domain, with the following exception:
99 The domain containing the SPM can only access Private data and Constant data
100 assets of other domains when required to implement the PSA Firmware Framework
101 API.
Ken Liu0ca70e02023-01-29 17:36:18 +0800102- I7. (Optional, added in FF-M 1.1) Constant data is not executable.
Ken Liu87b4f412020-06-04 11:13:39 +0800103
Jamie Fox66677052024-09-10 14:51:48 +0100104 The first 3 rules from ``I1`` to ``I3`` define the mandatory rules to comply
105 with the PSA security model, while ``I4`` to ``I7`` are optional rules to
106 enhance the isolation boundaries.
Ken Liu87b4f412020-06-04 11:13:39 +0800107
108 .. important::
Jamie Fox66677052024-09-10 14:51:48 +0100109 There is a table in chapter ``3.1.2`` of FF-M 1.0 [1]_ under ``I1`` that
110 lists the asset types and allowed access method. Preventing executable access
111 to constant data costs more hardware resources, so there is an optional rule
112 I7 created in FF-M 1.1 [2]_ to aid implementations with constrained hardware
113 resources.
Ken Liu87b4f412020-06-04 11:13:39 +0800114
115Hardware Infrastructure
116=======================
Jamie Fox66677052024-09-10 14:51:48 +0100117To implement a secure system, the hardware security framework (e.g. TrustZone or
118multiple-core) and their auxiliary components (e.g. SAU) are required to ensure
119the isolation between SPE and NSPE, as described in Trusted Base System
120Architecture for M (TBSA-M) [3]_.
Ken Liu87b4f412020-06-04 11:13:39 +0800121
122.. important::
123 The interface between secure and non-secure states needs to be fully
124 enumerated and audited to prove the integrity of the secure state
125 isolation.
126
127Besides this SPE and NSPE isolation mechanism, the following analyzes the
128implementation rules to find out the hardware requirements for isolation inside
129SPE domains:
130
Jamie Fox66677052024-09-10 14:51:48 +0100131- I1, I2 and I7: The assets can be categorized into 3 `Memory Asset Class`_,
132 each type has the specific access rules.
Ken Liu87b4f412020-06-04 11:13:39 +0800133- I3: The private data access from the prevented domain needs to be blocked.
134- I4: All the assets access from the prevented domain needs to be blocked.
135- I5: Code execution from all other domains (even the domain not prevented
136 from) needs to be blocked.
137- I6: All the assets access from all other domains (includes non-prevented
138 domain) needs to be blocked, but, SPM is an exception, which can access the
139 private data and constant data of the current domain.
140
141The above items list the requirements for memory access, here are two more
142points:
143
144- If the memory device or the peripheral are shared between multiple hosts
Jamie Fox66677052024-09-10 14:51:48 +0100145 (such as multiple CPU or DMA, etc.), specific hardware protection units need
Ken Liu87b4f412020-06-04 11:13:39 +0800146 to be available for validating accesses to that device or peripheral.
147- The MMIO range for Secure Partitions is not allowed to be overlapped, which
148 means each partition should have exclusive memory-mapped region if they
149 require a peripheral device. The memory-mapped region is regarded as
150 the private data so access to this area needs to be validated.
151
152************************
153Reference Implementation
154************************
155This chapter describes the isolation implementation inside SPE by using the
Jamie Fox66677052024-09-10 14:51:48 +0100156Armv8-M architecture component - Memory Protection Unit (MPU). The MPU can
Ken Liu87b4f412020-06-04 11:13:39 +0800157isolate CPU execution and data access.
158
159.. note::
160 Previous version M-profile architecture MPU setting is similar in concept but
161 the difference in practical register formats, which is not described in this
162 document.
163
164The MPU protects memory assets by regions. Each region represents a memory
165range with specific access attributes.
166
167.. note::
168 The maximum numbers of MPU regions are platform-specific.
169
170The SPM is running under the privileged mode for handling access from services.
171The MPU region for SPM needs to be available all the time since SPM controls
172the MPU setting while scheduling.
173
174Since partitions are scheduled by SPM, the MPU regions corresponding to the
175partitions can be configured dynamically while scheduling. Since there is only
176one running at a time and all others are deactivated, the SPM needs to set up
177necessary regions for each asset type in one partition only.
178
179There is re-usable code like the C-Runtime and RoT Service API which are same
180across different partitions. TF-M creates a Secure Partition Runtime Library
181(SPRTL) as a specific library shared by the Secure Partition. Please refer to
Ken Liu7f18fe32023-02-22 12:45:46 +0800182:doc:`Secure Partition Runtime Library </design_docs/services/secure_partition_runtime_library>`
Ken Liu87b4f412020-06-04 11:13:39 +0800183for more detail.
184
185.. note::
186 Enable SPRTL makes it hard to comply with the rules I4, I5 and I6,
187 duplicating the library code can be one solution but it is not "shared"
188 library anymore.
189
190As mentioned in the last chapter, MMIO needs extra MPU regions as private data.
191
192MPU Region Access Permission
193============================
Jamie Fox66677052024-09-10 14:51:48 +0100194The following content describes the memory access permission to represent the
195corresponding asset classes.
Ken Liu87b4f412020-06-04 11:13:39 +0800196
Jamie Fox66677052024-09-10 14:51:48 +0100197These access permissions are available on Armv8-M MPU:
Ken Liu87b4f412020-06-04 11:13:39 +0800198
199- Privileged Read-Only (RO)
200- All RO
201- Privileged Read-Write (RW)
202- All RW
Jamie Fox66677052024-09-10 14:51:48 +0100203- Execute Never (XN)
Ken Liu87b4f412020-06-04 11:13:39 +0800204
Jamie Fox66677052024-09-10 14:51:48 +0100205And one more Armv8.1-M access permission:
Ken Liu87b4f412020-06-04 11:13:39 +0800206
Jamie Fox66677052024-09-10 14:51:48 +0100207- Privileged Execute Never (PXN)
Ken Liu87b4f412020-06-04 11:13:39 +0800208
209The available regions type list:
210
211======== =========== =============== ========================================
212Type Attributes Privilege Level Asset
213======== =========== =============== ========================================
214P_RO RO Privileged PRoT Code
215P_ROXN RO + XN Privileged PRoT Constant Data
216P_RWXN RW + XN Privileged PRoT Private Data/Peripheral
217A_RO RO Any privilege Partition/SPRTL Code
218A_ROXN RO + XN Any privilege Partition/SPRTL Constant Data
219A_RWXN RW + XN Any privilege Partition/SPRTL Private Data/Peripheral
Jamie Fox66677052024-09-10 14:51:48 +0100220A_ROPXN RO + PXN Any privilege Armv8.1-M Partition Code
Ken Liu87b4f412020-06-04 11:13:39 +0800221======== =========== =============== ========================================
222
223Example Image Layout
224====================
225The secure firmware image contains components such as partitions, SPM and the
226shared code and data. Each component may have different class assets. There
227would be advantages if placing the assets from all components with the same
228access attributes into one same region:
229
230- The data relocating or clearing when booting can be done in one step instead
231 of breaking into fragments.
232- Assets with statically assigned access attribute can share the same MPU
233 region which saves regions.
234
235Take the TF-M existing implementation image layout as an example::
236
237 Level 1 Level 2 Level 3
238 Boundaries Boundaries Boundaries
239 +------------+----------+------------------------------------+
240 | | | PRoT SPM Code |
241 | | PRoT +------------------------------------+
242 | | Code | PRoT Service Code |
243 | Code +----------+------------------------------------+
244 | (ROM) | | Partition 1 Code |
245 | | +------------------------------------+
246 | | ARoT | Partition N Code |
247 | | Code +------------------------------------+
248 | | | SPRTL Code |
249 +------------+----------+------------------------------------+
250 Check [4] for more details between Code and Constant Data.
251 +------------+----------+------------------------------------+
252 | | PRoT | PRoT SPM Constant Data |
253 | | Constant +------------------------------------+
254 | | Data | PRoT Service Constant Data |
255 | Constant +----------+------------------------------------+
256 | Data | ARoT | Partition 1 Constant Data |
257 | (ROM) | Constant +------------------------------------+
258 | | Data | Partition N Constant Data |
259 | | +------------------------------------+
260 | | | SPRTL Constant Data |
261 +------------+----------+------------------------------------+
262
263 +------------+----------+------------------------------------+
264 | | PRoT | PRoT SPM Private Data |
265 | | Private +------------------------------------+
266 | | Data | PRoT Service Private Data |
267 | Private +----------+------------------------------------+
268 | Data | | Partition 1 Private Data |
269 | (RAM) | ARoT +------------------------------------+
270 | | Private | Partition N Private Data |
271 | | Data +------------------------------------+
272 | | | SPRTL Private Data |
273 +------------+----------+------------------------------------+
274
275.. note::
276 1. Multiple binaries image implementation could also reference this layout if
277 its hardware protection unit can cover the exact boundaries mentioned
278 above.
Jamie Fox66677052024-09-10 14:51:48 +0100279 2. Private data includes both initialized and zero-initialized (ZI) sections.
280 Check chapter ``3.1.1`` of FF-M [1]_ for the details.
Ken Liu87b4f412020-06-04 11:13:39 +0800281 3. This diagram shows the boundaries but not orders. The order of regions
282 inside one upper region can be adjusted freely.
283 4. As described in the ``important`` of `Memory Asset Class`_, the setting
284 between Code and Constant Data can be skipped if the executable access
285 method is not applied to constant data. In this case, the groups of Code
286 and Constant Data can be combined or even mixed -- but the boundary
287 between PRoT and ARoT are still required under level higher than 1.
288
289Example Region Numbers under Isolation Level 3
290==============================================
Jamie Fox66677052024-09-10 14:51:48 +0100291The following table lists the required regions to comply with the rules for
Ken Liu87b4f412020-06-04 11:13:39 +0800292implementing isolation level 3. The level 1 and level 2 can be exported by
293simplifying the items in level 3 table.
294
295.. important::
296 The table described below is trying to be shared between all supported
Jamie Fox66677052024-09-10 14:51:48 +0100297 platforms in Trusted Firmware-M. It is obvious that some platforms have
Ken Liu87b4f412020-06-04 11:13:39 +0800298 special characteristics. In that case, the specific layout table for a
299 particular platform can be totally redesigned but need to fulfil the
300 isolation level requirements.
301
Jamie Fox66677052024-09-10 14:51:48 +0100302- Only the running partition's assets are covered since the inactive partitions
303 do not need regions.
304- ``X`` indicates the existence of this region can't comply with the rule.
305- An ``ATTR + n`` represent extra ``n`` regions are necessary.
306- The table assumes each rule is in addition to the rules in previous columns
307 (but the FF-M permits any combination of optional rules).
Ken Liu87b4f412020-06-04 11:13:39 +0800308
Jamie Fox66677052024-09-10 14:51:48 +0100309The following table lists the required regions to comply with the rules:
Ken Liu87b4f412020-06-04 11:13:39 +0800310
Jamie Fox66677052024-09-10 14:51:48 +0100311+-------------------+-------------+-------------+-------------+-------------+
312| Region Purpose | I1 I2 I3 I7 | I4 | I5 | I6 |
313+===================+=============+=============+=============+=============+
314| PRoT SPM Code | A_RO | P_RO | P_RO | P_RO |
315+-------------------+ | | +-------------+
316| PRoT Service Code | | | | A_ROPXN |
317+-------------------+ +-------------+-------------+ |
318| Active Partition | | A_RO | A_ROPXN | |
319| Code | | | | |
320+-------------------+ +-------------+-------------+-------------+
321| SPRTL Code | | A_RO | A_RO | ``X`` |
322+-------------------+-------------+-------------+-------------+-------------+
323| PRoT SPM RO | A_ROXN | P_ROXN | P_ROXN | P_ROXN |
324+-------------------+ | | +-------------+
325| PRoT Service RO | | | | A_ROXN |
326+-------------------+ +-------------+-------------+ |
327| Active Partition | | A_ROXN | A_ROXN | |
328| RO | | | | |
329+-------------------+ +-------------+-------------+-------------+
330| SPRTL RO | | A_ROXN | A_ROXN | ``X`` |
331+-------------------+-------------+-------------+-------------+-------------+
332| PRoT SPM RW | P_RWXN | P_RWXN | P_RWXN | P_RWXN |
333+-------------------+ | | +-------------+
334| PRoT Service RW | | | | A_RWXN |
335+-------------------+-------------+-------------+-------------+ |
336| Active Partition | A_RWXN | A_RWXN | A_RWXN | |
337| RW | | | | |
338+-------------------+-------------+-------------+-------------+-------------+
339| SPRTL RW [5] | A_RWXN + 1 | A_RWXN + 1 | A_RWXN + 1 | ``X`` |
340+-------------------+-------------+-------------+-------------+-------------+
341| Partition Periph | A_RWXN + n | A_RWXN + n | A_RWXN + n | A_RWXN + n |
342+-------------------+-------------+-------------+-------------+-------------+
343| Total Numbers | [1] | [2] | [3] | [4] |
344+-------------------+-------------+-------------+-------------+-------------+
Ken Liu87b4f412020-06-04 11:13:39 +0800345
346.. note::
Jamie Fox66677052024-09-10 14:51:48 +0100347 1. Total number = A_RO + A_ROXN + P_RWXN + (2 + n)A_RWXN = ``5 + n``, where
348 ``n`` is the maximum number of peripherals needed by one partition.
349 2. Total number = [1] + P_RO + A_RO + P_ROXN + A_ROXN = ``9 + n`` (or
350 ``6 + n`` without SPRTL).
351 3. Total number = [2] = ``9 + n``, and Armv8.1-M PXN is required.
352 4. Total number = P_RO + A_ROPXN + P_ROXN + A_ROXN + P_RWXN + (1 + n)A_RWXN =
353 ``6 + n``, but SPRTL cannot be used, and Armv8.1-M PXN is required. To
354 comply with this rule, the PSA RoT Services need to be implemented as
355 Secure Partitions.
Ken Liu87b4f412020-06-04 11:13:39 +0800356 5. This data belongs to SPRTL RW but it is set as Read-Only and only SPM
Jamie Fox66677052024-09-10 14:51:48 +0100357 can update this region with the active partition's metadata for
Ken Liu87b4f412020-06-04 11:13:39 +0800358 implementing functions with owner SP's context, such as heap functions.
359 This region can be skipped if there is no metadata required (such as no
360 heap functionalities required).
361
362 The memory-mapped regions for peripherals have different memory access
Jamie Fox66677052024-09-10 14:51:48 +0100363 attributes in general, they are standalone regions in the MPU even though
364 their attributes covers 'A_RWXN'.
365
366TF-M provides the reference linker scripts ``tfm_isolation_s.sct.template``,
367``tfm_isolation_s.ld.template``, and ``tfm_isolation_s.icf.template`` for the
368Armclang, GCC, and IAR compilers in the ``platform/ext/common`` directory. These
369linker scripts arrange the SPE's memory by attribute to aid the implementation
370of the isolation rules.
371
372The reference isolation HAL for Armv8-M and Armv8.1-M platforms in
373``platform/ext/common/tfm_hal_isolation_v8m.c`` uses the memory position tags
374defined by the linker scripts to set up the MPU region base and limit addresses.
375It implements isolation rules I1, I2, I3 and I7 for isolation levels 1 to 3. It
376partially implements rule I4 by statically partitioning code into privileged and
377unprivileged read-only regions but collecting all constant data into a single
378unprivileged, read-only, execute-never region, which provides a good level
379of protection against ROP attacks by limiting the amount of executable memory.
380On Armv8.1-M targets, it statically configures all Application RoT Partition
381code as PXN, which is sufficient to satisfy rule I5 in isolation level 2, but
382not in isolation level 3, where it would require dynamically mapping only the
383active partition's code region.
384
385TF-M platforms may replace the reference linker scripts and/or isolation HAL
386with a customized implementation, but it must meet at least isolation rules I1,
387I2 and I3 to comply with the PSA security model.
Ken Liu87b4f412020-06-04 11:13:39 +0800388
Ken Liu297c2aa2023-02-23 11:22:33 +0800389Default access rules
390====================
391Hardware protection components MAY have the capability to collect regions
392not explicitly configured in static or runtime settings, and then apply
Jamie Fox66677052024-09-10 14:51:48 +0100393default access rules to these regions. Furthermore, one default rule can be
Ken Liu297c2aa2023-02-23 11:22:33 +0800394applied to multiple non-contiguous regions which makes them share a common
Jamie Fox66677052024-09-10 14:51:48 +0100395boundary. This operation sets up a standalone 'region' the same as other
Ken Liu297c2aa2023-02-23 11:22:33 +0800396explicitly configured regions. And it doesn't affect the analysis summary
397above - just be aware that some regions listed in the table MAY not be
398explicitly configured.
399
400Take the MPU as an example, MPU can assign a default privileged access
Jamie Fox66677052024-09-10 14:51:48 +0100401attribute to the regions (e.g. SPM and PRoT regions) not explicitly configured.
Ken Liu297c2aa2023-02-23 11:22:33 +0800402This feature can reduce required MPU regions and ease the programming because
403regions can be put non-address-contiguous and skip the explicit configuration.
404
Ken Liu87b4f412020-06-04 11:13:39 +0800405.. important::
Jamie Fox66677052024-09-10 14:51:48 +0100406 When this default access rules mechanism is applied, the implicitly configured
407 regions must be reviewed to ensure the isolation boundaries are set correctly.
Ken Liu87b4f412020-06-04 11:13:39 +0800408
409Interfaces
410==========
411The isolation implementation is based on the HAL framework. The SPM relies on
412the HAL API to perform the necessary isolation related operations.
413
414The requirement the software need to do are these:
415
416- Create enough isolation protection at the early stage of system booting, just
417 need to focus on the SPM domain.
418- Create an isolation domain between secure and non-secure before the jump to
419 the non-secure world.
420- Create an isolation domain for each Secure Partition after the Secure
421 Partition is loaded and before jumping to its entry point. The isolation
422 domain should cover all the assets of the Secure Partition, include all its
423 memory, interrupts, and peripherals.
424- Switch isolation domains when scheduling different Secure Partitions.
425- It is also a requirement that the platform needs to help to check if the
426 caller of the PSA APIs is permitted to access some memory ranges.
427
Minos Galanakisba3d41c2020-11-20 10:28:47 +0000428The design document
Anton Komlevb3f64662023-01-28 11:53:05 +0000429:doc:`TF-M Hardware Abstraction Layer </design_docs/software/hardware_abstraction_layer>`
Minos Galanakisba3d41c2020-11-20 10:28:47 +0000430gives a detail design, include the platform initialization, isolation
431interfaces. Please refer to it for more detail.
Ken Liu87b4f412020-06-04 11:13:39 +0800432
Jamie Fox66677052024-09-10 14:51:48 +0100433**********
434References
435**********
Ken Liu87b4f412020-06-04 11:13:39 +0800436
Jamie Fox66677052024-09-10 14:51:48 +0100437.. [1] `Arm PSA Firmware Framework for M 1.0 (FF-M 1.0) <https://developer.arm.com/documentation/den0063/latest/>`_
438.. [2] `Arm Firmware Framework for M 1.1 Extension (FF-M 1.1) <https://developer.arm.com/documentation/aes0039/latest/>`_
439.. [3] `Arm Trusted Base System Architecture for M (TBSA-M) <https://www.arm.com/en/architecture/security-features/platform-security>`_
Ken Liu87b4f412020-06-04 11:13:39 +0800440
441--------------
442
Jamie Fox66677052024-09-10 14:51:48 +0100443*Copyright (c) 2020-2024, Arm Limited. All rights reserved.*