Nicola Mazzucato | fc1bf77 | 2024-05-07 16:21:33 +0100 | [diff] [blame] | 1 | ################# |
| 2 | Branch Protection |
| 3 | ################# |
| 4 | |
| 5 | The Branch Protection is an optional feature that can help with mitigation of |
| 6 | common exploits through undesired branching in code. |
| 7 | |
| 8 | The Branch Protection feature leverages the Pointer Authentication and Branch |
| 9 | Target Identification extension (PACBTI) which is optional and available in |
| 10 | Armv8.1-M architecture. |
| 11 | |
| 12 | PACBTI is designed to mitigate Return-Oriented Programming (ROP) and |
| 13 | Jump-Oriented Programming (JOP) security exploit attacks. |
| 14 | |
| 15 | |
| 16 | Pointer authentication |
| 17 | ====================== |
| 18 | |
| 19 | Pointer authentication (PAC) is a technique by which the pointer is "signed". |
| 20 | This signed pointer is generated by the hardware by combining a modifier, a |
| 21 | secret key and the pointer itself through a hardware cryptographic mechanism. |
| 22 | |
| 23 | The generated signed pointer is produced at the beginning of a subroutine or |
| 24 | function. |
| 25 | On returning from the subroutine/function another signed pointer is generated |
| 26 | and compared with the previous signed pointer. If they match, then the pointer |
| 27 | (return address) has not been tampered and there are no side-effects. |
| 28 | Otherwise the validating instruction generates a UsageFault exception. |
| 29 | |
| 30 | All the above functionality is achieved by introducing specific instructions at |
| 31 | the beginning and at the end of the subroutine/function. This addition is |
| 32 | controlled by compiler options, when supported. |
| 33 | |
| 34 | To enable PAC in your platform, TF-M supports the following build options: |
| 35 | |
| 36 | - BRANCH_PROTECTION_PACRET |
| 37 | - BRANCH_PROTECTION_PACRET_LEAF |
| 38 | |
| 39 | One of the above values can be assigned to ``CONFIG_TFM_BRANCH_PROTECTION_FEAT`` |
| 40 | |
| 41 | ``BRANCH_PROTECTION_PACRET_LEAF`` extends ``BRANCH_PROTECTION_PACRET`` when PAC |
| 42 | is desired also in leaf functions. |
| 43 | |
| 44 | |
| 45 | Branch target identification |
| 46 | ============================ |
| 47 | |
| 48 | Branch Target Identification (BTI) can mitigate some of the JOP attacks so that |
| 49 | indirect branches can only allow target instructions. Such instructions are also |
| 50 | called landing pads. |
| 51 | In other words, an indirect branch can only "land" where a specific instruction |
| 52 | is present, otherwise the branch has been compromised and a UsageFault exception |
| 53 | is raised. |
| 54 | |
| 55 | The above functionality is achieved by introducing specific instructions at the |
| 56 | beginning of executable code. |
| 57 | |
| 58 | To enable BTI in your platform, TF-M supports the following build option: |
| 59 | |
| 60 | - BRANCH_PROTECTION_BTI |
| 61 | |
| 62 | One of the above values can be assigned to ``CONFIG_TFM_BRANCH_PROTECTION_FEAT`` |
| 63 | |
| 64 | |
| 65 | PAC and BTI |
| 66 | =========== |
| 67 | |
| 68 | It is possible to have some combinations of the PAC and BTI options above. |
| 69 | The allowed values for ``CONFIG_TFM_BRANCH_PROTECTION_FEAT`` are listed below, |
| 70 | but only one option can be used: |
| 71 | |
| 72 | * ``BRANCH_PROTECTION_DISABLED`` - PACBTI feature is disabled |
| 73 | * ``BRANCH_PROTECTION_NONE`` - PACBTI instructions are not generated |
| 74 | * ``BRANCH_PROTECTION_STANDARD`` - Enables pointer authentication and branch target identification, leaf functions excluded |
| 75 | * ``BRANCH_PROTECTION_PACRET`` - Enables pointer authentication only, leaf functions excluded |
| 76 | * ``BRANCH_PROTECTION_PACRET_LEAF`` - Enables pointer authentication on all functions, including leaf functions |
| 77 | * ``BRANCH_PROTECTION_BTI`` - Enables branch target identification only |
| 78 | |
| 79 | Note that PACBTI is conditional to both architecture support and compiler |
| 80 | support. |
| 81 | |
| 82 | The build system performs checks to ensure that support is available and |
| 83 | terminates the build process if the required conditions are not met. |
| 84 | |
| 85 | |
Nicola Mazzucato | e992c78 | 2024-08-21 10:12:13 +0100 | [diff] [blame^] | 86 | Limitations |
| 87 | =========== |
| 88 | |
| 89 | Currently PACBTI is supported only for Arm Compiler. |
| 90 | Even though GNUARM supports PACBTI, some features are missing that prevent all |
| 91 | the component integration to successfully work together. |
| 92 | It may be possible in the future to extend support for other compilers. |
| 93 | |
Nicola Mazzucato | fc1bf77 | 2024-05-07 16:21:33 +0100 | [diff] [blame] | 94 | -------------- |
| 95 | |
| 96 | For further details on PACBTI features refer to: |
| 97 | |
| 98 | `Armv8-M Architecture Reference Manual <https://developer.arm.com/documentation/ddi0553/latest>`_ |
| 99 | |
| 100 | `Armv8.1-M Pointer Authentication and Branch Target Identification Extension <https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension>`_ |
| 101 | |
| 102 | -------------- |
| 103 | |
| 104 | *Copyright (c) 2024, Arm Limited. All rights reserved.* |