blob: c35f39b32ebdcea8d3d5fc62f26301cf3a09f307 [file] [log] [blame]
Nicola Mazzucatofc1bf772024-05-07 16:21:33 +01001#################
2Branch Protection
3#################
4
5The Branch Protection is an optional feature that can help with mitigation of
6common exploits through undesired branching in code.
7
8The Branch Protection feature leverages the Pointer Authentication and Branch
9Target Identification extension (PACBTI) which is optional and available in
10Armv8.1-M architecture.
11
12PACBTI is designed to mitigate Return-Oriented Programming (ROP) and
13Jump-Oriented Programming (JOP) security exploit attacks.
14
15
16Pointer authentication
17======================
18
19Pointer authentication (PAC) is a technique by which the pointer is "signed".
20This signed pointer is generated by the hardware by combining a modifier, a
21secret key and the pointer itself through a hardware cryptographic mechanism.
22
23The generated signed pointer is produced at the beginning of a subroutine or
24function.
25On returning from the subroutine/function another signed pointer is generated
26and 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.
28Otherwise the validating instruction generates a UsageFault exception.
29
30All the above functionality is achieved by introducing specific instructions at
31the beginning and at the end of the subroutine/function. This addition is
32controlled by compiler options, when supported.
33
34To enable PAC in your platform, TF-M supports the following build options:
35
36 - BRANCH_PROTECTION_PACRET
37 - BRANCH_PROTECTION_PACRET_LEAF
38
39One 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
42is desired also in leaf functions.
43
44
45Branch target identification
46============================
47
48Branch Target Identification (BTI) can mitigate some of the JOP attacks so that
49indirect branches can only allow target instructions. Such instructions are also
50called landing pads.
51In other words, an indirect branch can only "land" where a specific instruction
52is present, otherwise the branch has been compromised and a UsageFault exception
53is raised.
54
55The above functionality is achieved by introducing specific instructions at the
56beginning of executable code.
57
58To enable BTI in your platform, TF-M supports the following build option:
59
60 - BRANCH_PROTECTION_BTI
61
62One of the above values can be assigned to ``CONFIG_TFM_BRANCH_PROTECTION_FEAT``
63
64
65PAC and BTI
66===========
67
68It is possible to have some combinations of the PAC and BTI options above.
69The allowed values for ``CONFIG_TFM_BRANCH_PROTECTION_FEAT`` are listed below,
70but 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
79Note that PACBTI is conditional to both architecture support and compiler
80support.
81
82The build system performs checks to ensure that support is available and
83terminates the build process if the required conditions are not met.
84
85
86--------------
87
88For further details on PACBTI features refer to:
89
90`Armv8-M Architecture Reference Manual <https://developer.arm.com/documentation/ddi0553/latest>`_
91
92`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>`_
93
94--------------
95
96*Copyright (c) 2024, Arm Limited. All rights reserved.*