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