blob: dd3140dd10c95aad97ec737592168e762f356f87 [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
8This document analyzes the isolation rules of implementing ``FF-M 1.0``
9isolation and introduces the reference implementation in TF-M, which
10complies the rules by operating the hardware and software resources.
11
12.. note::
Anton Komlev3356ba32022-03-31 22:02:11 +010013 Reference the document :doc:`Glossary </glossary>` for terms
Ken Liu87b4f412020-06-04 11:13:39 +080014 and abbreviations.
15
16************
17Introduction
18************
19This chapter describes the definitions from ``FF-M`` and analyzes
20the possible implementation keypoints.
21
22Isolation Levels
23================
24There are 3 isolation levels (1-3) defined in ``FF-M``, the greater level
25number has more isolation boundaries.
26
27The definition for Isolation Level 1:
28
29- L1.1 NPSE needs protection from nobody.
30- L1.2 SPE needs protection from NSPE.
31
32The definition for Isolation Level 2:
33
34- L2.1 NPSE needs protection from nobody.
35- L2.2 Application Root of Trust (ARoT) needs protection from NSPE.
36- L2.3 PSA Root of Trust (PRoT) needs protection from NSPE and ARoT.
37
38The definition for Isolation Level 3:
39
40- L3.1 NPSE needs protection from nobody.
41- L3.2 Secure Partition needs protection from NSPE and other Secure Partitions.
42- L3.3 PSA Root of Trust (RoT) domain needs protection from NSPE and all Secure
43 Partitions.
44
45.. important::
Ken Liue6b477c2022-08-22 10:56:24 +080046 A Secure Partition RoT Service is a Root of Trust Service implemented within
47 a Secure Partition. An Application RoT Service must be implemented as
48 a Secure Partition RoT Service. But it is implementation-defined whether a
49 PSA RoT Service is a Secure Partition RoT Service.
50
51 Here listed several possible PSA RoT Service implementation mechanisms:
52
53 1. Implement them in Secure Partitions with respective boundaries.
54 2. Implement them in Secure Partitions, but no boundaries between these
55 Secure Partitions.
56 3. Implement them in a customized way instead of Secure Partitions.
57
58 TF-M chooses the 2nd option to balance performance and complexity.
Ken Liu87b4f412020-06-04 11:13:39 +080059
60Isolation Rules
61===============
62The essence of isolation is to protect the assets of one protection domain from
63being accessed from other domains. The isolation levels define where the
64isolation boundaries should be placed, the isolation rules define the strength
65of the isolation the boundaries should offer.
66
67.. note::
68 In general, assets include not only ROM/RAM and peripherals. For the detail
69 information about the memory assets and peripheral, please
Anton Komlevfb835402022-08-09 13:04:04 +010070 refer to `Firmware Framework for M (FF-M)`_.
Ken Liu87b4f412020-06-04 11:13:39 +080071
72Memory Asset Class
73------------------
Anton Komlevfb835402022-08-09 13:04:04 +010074There are 3 memory asset classes defined in `Firmware Framework for M (FF-M)`_:
Ken Liu87b4f412020-06-04 11:13:39 +080075
76- Code
77- Constant data
78- Private data
79
80There are 6 isolation rules for protecting assets. Here lists the simplified
81description for the rules, check chapter ``3.1.2`` of ``FF-M 1.0`` for the
82original description:
83
84- I1. Only Code is executable.
85- I2. Only private data is writable.
86- I3. If domain A needs protection from domain B, then Private data in domain A
87 cannot be accessed by domain B.
88- I4. (Optional) If domain A needs protection from domain B, then Code and
89 Constant data in domain A is not readable or executable by domain B.
90- I5. (Optional) Code in a domain is not executable by any other domain.
91- I6. (Optional) All assets in a domain are private to that domain and cannot be
92 accessed by any other domain, with the following exception:
93 The domain containing the SPM can only access Private data and Constant data
94 assets of other domains when required to implement the PSA Firmware Framework
95 API.
96
97 The first 3 rules from ``I1`` to ``I3`` defines the mandatory rules to comply
98 the isolation, while ``I4`` to ``I6`` are optional rules to enhance the
99 isolation boundaries.
100
101 .. important::
102 There is a table in the chapter ``3.1.2`` of ``FF-M 1.0`` under ``I1`` lists
103 the asset types and allowed access method. Preventing executable access on
104 constant data costs more hardware resources, so the requirement in the table
105 about constant data can be regarded as a recommendation instead of a
106 mandatory item under some hardware resource-constrained cases.
107
108Hardware Infrastructure
109=======================
110To implement a secure system, the hardware security framework (TrustZone or
111multiple-core e.g.) and their auxiliary components (SAU e.g.) are required
112to ensure the isolation between SPE and NSPE. The requirements:
113
114.. important::
115 The interface between secure and non-secure states needs to be fully
116 enumerated and audited to prove the integrity of the secure state
117 isolation.
118
119Besides this SPE and NSPE isolation mechanism, the following analyzes the
120implementation rules to find out the hardware requirements for isolation inside
121SPE domains:
122
123- I1 and I2: The assets can be categorized into 3 `Memory Asset Class`_, each
124 type has the specific access rules.
125- I3: The private data access from the prevented domain needs to be blocked.
126- I4: All the assets access from the prevented domain needs to be blocked.
127- I5: Code execution from all other domains (even the domain not prevented
128 from) needs to be blocked.
129- I6: All the assets access from all other domains (includes non-prevented
130 domain) needs to be blocked, but, SPM is an exception, which can access the
131 private data and constant data of the current domain.
132
133The above items list the requirements for memory access, here are two more
134points:
135
136- If the memory device or the peripheral are shared between multiple hosts
137 (Such as multiple CPU or DMA, etc), specific hardware protection units need
138 to be available for validating accesses to that device or peripheral.
139- The MMIO range for Secure Partitions is not allowed to be overlapped, which
140 means each partition should have exclusive memory-mapped region if they
141 require a peripheral device. The memory-mapped region is regarded as
142 the private data so access to this area needs to be validated.
143
144************************
145Reference Implementation
146************************
147This chapter describes the isolation implementation inside SPE by using the
148Armv8m architecture component - Memory Protection Unit (MPU). The MPU can
149isolate CPU execution and data access.
150
151.. note::
152 Previous version M-profile architecture MPU setting is similar in concept but
153 the difference in practical register formats, which is not described in this
154 document.
155
156The MPU protects memory assets by regions. Each region represents a memory
157range with specific access attributes.
158
159.. note::
160 The maximum numbers of MPU regions are platform-specific.
161
162The SPM is running under the privileged mode for handling access from services.
163The MPU region for SPM needs to be available all the time since SPM controls
164the MPU setting while scheduling.
165
166Since partitions are scheduled by SPM, the MPU regions corresponding to the
167partitions can be configured dynamically while scheduling. Since there is only
168one running at a time and all others are deactivated, the SPM needs to set up
169necessary regions for each asset type in one partition only.
170
171There is re-usable code like the C-Runtime and RoT Service API which are same
172across different partitions. TF-M creates a Secure Partition Runtime Library
173(SPRTL) as a specific library shared by the Secure Partition. Please refer to
174:doc:`Secure Partition Runtime Library <tfm_secure_partition_runtime_library>`
175for more detail.
176
177.. note::
178 Enable SPRTL makes it hard to comply with the rules I4, I5 and I6,
179 duplicating the library code can be one solution but it is not "shared"
180 library anymore.
181
182As mentioned in the last chapter, MMIO needs extra MPU regions as private data.
183
184MPU Region Access Permission
185============================
186The following content would mention the memory access permission to represent
187the corresponded asset classes.
188
189These access permissions are available on Armv8m MPU:
190
191- Privileged Read-Only (RO)
192- All RO
193- Privileged Read-Write (RW)
194- All RW
195- Execution Never (XN)
196
197And one more Armv8.1M access permssion:
198
199- Privileged Execution Never (PXN)
200
201The available regions type list:
202
203======== =========== =============== ========================================
204Type Attributes Privilege Level Asset
205======== =========== =============== ========================================
206P_RO RO Privileged PRoT Code
207P_ROXN RO + XN Privileged PRoT Constant Data
208P_RWXN RW + XN Privileged PRoT Private Data/Peripheral
209A_RO RO Any privilege Partition/SPRTL Code
210A_ROXN RO + XN Any privilege Partition/SPRTL Constant Data
211A_RWXN RW + XN Any privilege Partition/SPRTL Private Data/Peripheral
212A_ROPXN RO + PXN Any privilege Armv8.1M Partition/SPRTL Code
213======== =========== =============== ========================================
214
215Example Image Layout
216====================
217The secure firmware image contains components such as partitions, SPM and the
218shared code and data. Each component may have different class assets. There
219would be advantages if placing the assets from all components with the same
220access attributes into one same region:
221
222- The data relocating or clearing when booting can be done in one step instead
223 of breaking into fragments.
224- Assets with statically assigned access attribute can share the same MPU
225 region which saves regions.
226
227Take the TF-M existing implementation image layout as an example::
228
229 Level 1 Level 2 Level 3
230 Boundaries Boundaries Boundaries
231 +------------+----------+------------------------------------+
232 | | | PRoT SPM Code |
233 | | PRoT +------------------------------------+
234 | | Code | PRoT Service Code |
235 | Code +----------+------------------------------------+
236 | (ROM) | | Partition 1 Code |
237 | | +------------------------------------+
238 | | ARoT | Partition N Code |
239 | | Code +------------------------------------+
240 | | | SPRTL Code |
241 +------------+----------+------------------------------------+
242 Check [4] for more details between Code and Constant Data.
243 +------------+----------+------------------------------------+
244 | | PRoT | PRoT SPM Constant Data |
245 | | Constant +------------------------------------+
246 | | Data | PRoT Service Constant Data |
247 | Constant +----------+------------------------------------+
248 | Data | ARoT | Partition 1 Constant Data |
249 | (ROM) | Constant +------------------------------------+
250 | | Data | Partition N Constant Data |
251 | | +------------------------------------+
252 | | | SPRTL Constant Data |
253 +------------+----------+------------------------------------+
254
255 +------------+----------+------------------------------------+
256 | | PRoT | PRoT SPM Private Data |
257 | | Private +------------------------------------+
258 | | Data | PRoT Service Private Data |
259 | Private +----------+------------------------------------+
260 | Data | | Partition 1 Private Data |
261 | (RAM) | ARoT +------------------------------------+
262 | | Private | Partition N Private Data |
263 | | Data +------------------------------------+
264 | | | SPRTL Private Data |
265 +------------+----------+------------------------------------+
266
267.. note::
268 1. Multiple binaries image implementation could also reference this layout if
269 its hardware protection unit can cover the exact boundaries mentioned
270 above.
271 2. Private data includes both initialized and non-initialized (ZI) sections.
272 Check chapter ``3.1.1`` of ``FF-M`` for the details.
273 3. This diagram shows the boundaries but not orders. The order of regions
274 inside one upper region can be adjusted freely.
275 4. As described in the ``important`` of `Memory Asset Class`_, the setting
276 between Code and Constant Data can be skipped if the executable access
277 method is not applied to constant data. In this case, the groups of Code
278 and Constant Data can be combined or even mixed -- but the boundary
279 between PRoT and ARoT are still required under level higher than 1.
280
281Example Region Numbers under Isolation Level 3
282==============================================
283The following table lists the required regions while complying the rules for
284implementing isolation level 3. The level 1 and level 2 can be exported by
285simplifying the items in level 3 table.
286
287.. important::
288 The table described below is trying to be shared between all supported
289 platforms in Trusted Firmware - M. It is obvious that some platforms have
290 special characteristics. In that case, the specific layout table for a
291 particular platform can be totally redesigned but need to fulfil the
292 isolation level requirements.
293
294- Care only the running partitions assets since deactivated partition does not
295 need regions.
296- `X` indicates the existence of this region can't comply with the rule.
297- An `ATTR + n` represent extra ``n`` regions are necessary.
298- Here assumes the rules with a greater number covers the requirements in the
299 rules with less number.
300
301Here lists the required regions while complying with the rules:
302
303+------------------+-------------+-------------+-------------+-------------+
304| Region Purpose | I1 I2 I3 | I4 | I5 | I6 |
305+==================+=============+=============+=============+=============+
306| PRoT SPM Code | A_RO | P_RO | P_RO | P_RO |
307+------------------+ | | +-------------+
308| PRoT Service Code| | | | A_ROPXN |
309+------------------+ +-------------+-------------+ |
310| Active Partition | | A_RO | A_ROPXN | |
311| Code | | | | |
312+------------------+ +-------------+-------------+-------------+
313| SPRTL Code | | ``X`` | ``X`` | ``X`` |
314+------------------+-------------+-------------+-------------+-------------+
315| PRoT SPM RO | A_ROXN | P_ROXN | P_ROXN | P_ROXN |
316+------------------+ | | +-------------+
317| PRoT Service RO | | | | A_ROXN |
318+------------------+ +-------------+-------------+ |
319| Active Partition | | A_ROXN | A_ROXN | |
320| RO | | | | |
321+------------------+ +-------------+-------------+-------------+
322| SPRTL RO | | ``X`` | ``X`` | ``X`` |
323+------------------+-------------+-------------+-------------+-------------+
324| PRoT SPM RW | P_RWXN | P_RWXN | P_RWXN | P_RWXN |
325+------------------+ | | +-------------+
326| PRoT Service RW | | | | A_RWXN |
327+------------------+-------------+-------------+-------------+ |
328| Active Partition | A_RWXN | A_RWXN | A_RWXN | |
329| RW | | | | |
330+------------------+-------------+-------------+-------------+-------------+
331| SPRTL RW [5] | A_RWXN + 1 | ``X`` | ``X`` | ``X`` |
332+------------------+-------------+-------------+-------------+-------------+
333| Partition Peri | A_RWXN + n | A_RWXN + n | A_RWXN + n | A_RWXN + n |
334+------------------+-------------+-------------+-------------+-------------+
335| Total Numbers | [1] | [2] | [3] | [4] |
336+------------------+-------------+-------------+-------------+-------------+
337
338.. note::
339 1. Total number = A_RO + A_ROXN + P_RWXN + A_RWXN + (1 + n)A_RWXN, while
340 n equals the maximum peripheral numbers needed by one partition. This is
341 the configuration chosen by the reference implementation.
342 2. Total number = P_RO + P_ROXN + P_RWXN + A_RO + A_ROXN + (1 + n)A_RWXN,
343 the minimal result is `6`, and SPRTL can not be applied.
344 3. Total number = P_RO + P_ROXN + P_RWXN + A_ROXN + (1 + n)A_RWXN +
345 A_ROPXN, the minimal result is `6`, SPRTL can not be applied, and PXN
346 is required.
347 4. Total number = P_RO + P_ROXN + P_RWXN + A_ROXN + (1 + n)A_RWXN +
348 A_ROPXN, the minimal result is `6`, SPRTL can not be applied, and PXN
349 is required. To comply with this rule, the PSA RoT Service needs
350 to be implemented as Secure Partitions.
351 5. This data belongs to SPRTL RW but it is set as Read-Only and only SPM
352 can update this region with the activate partition's metadata for
353 implementing functions with owner SP's context, such as heap functions.
354 This region can be skipped if there is no metadata required (such as no
355 heap functionalities required).
356
357 The memory-mapped regions for peripherals have different memory access
358 attributes in general, they are standalone regions in MPU even their
359 attributes covers 'A_RWXN'.
360
361.. important::
362 The default memory map is not involved in this example, because it grants PSA
363 RoT domain program (especially SPM) the ability to access the place not
364 covered in an explicitly defined region. In a system lack of enough MPU
365 regions, the default memory map can be applied, in this case, the whole image
366 layout needs to be audited to find out if the uncovered region contains
367 garbage or gadget data which could provide an attack.
368
369Interfaces
370==========
371The isolation implementation is based on the HAL framework. The SPM relies on
372the HAL API to perform the necessary isolation related operations.
373
374The requirement the software need to do are these:
375
376- Create enough isolation protection at the early stage of system booting, just
377 need to focus on the SPM domain.
378- Create an isolation domain between secure and non-secure before the jump to
379 the non-secure world.
380- Create an isolation domain for each Secure Partition after the Secure
381 Partition is loaded and before jumping to its entry point. The isolation
382 domain should cover all the assets of the Secure Partition, include all its
383 memory, interrupts, and peripherals.
384- Switch isolation domains when scheduling different Secure Partitions.
385- It is also a requirement that the platform needs to help to check if the
386 caller of the PSA APIs is permitted to access some memory ranges.
387
Minos Galanakisba3d41c2020-11-20 10:28:47 +0000388
389The design document
390:doc:`TF-M Hardware Abstraction Layer <hardware_abstraction_layer>`
391gives a detail design, include the platform initialization, isolation
392interfaces. Please refer to it for more detail.
Ken Liu87b4f412020-06-04 11:13:39 +0800393
394Appendix
395========
Anton Komlevfb835402022-08-09 13:04:04 +0100396| `Firmware Framework for M (FF-M)`_
Ken Liu87b4f412020-06-04 11:13:39 +0800397
Anton Komlevfb835402022-08-09 13:04:04 +0100398.. _Firmware Framework for M (FF-M):
Anton Komlevda5fb7c2022-04-27 19:04:23 +0100399 https://www.arm.com/architecture/security-features/platform-security
Ken Liu87b4f412020-06-04 11:13:39 +0800400
Anton Komlevfb835402022-08-09 13:04:04 +0100401| `Trusted Base System Architecture for M (TBSA-M)`_
Ken Liu87b4f412020-06-04 11:13:39 +0800402
Anton Komlevfb835402022-08-09 13:04:04 +0100403.. _Trusted Base System Architecture for M (TBSA-M):
404 https://www.arm.com/architecture/security-features/platform-security
Ken Liu87b4f412020-06-04 11:13:39 +0800405
406--------------
407
Anton Komlevfb835402022-08-09 13:04:04 +0100408*Copyright (c) 2020-2022, Arm Limited. All rights reserved.*