Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: docs: document pointer authentication

Now that we've added code to support pointer authentication, add some
documentation so that people can figure out if/how to use it.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
Reviewed-by: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>

authored by

Mark Rutland and committed by
Will Deacon
fbedc599 84931327

+116
+8
Documentation/arm64/booting.txt
··· 205 205 ICC_SRE_EL2.SRE (bit 0) must be initialised to 0b0. 206 206 - The DT or ACPI tables must describe a GICv2 interrupt controller. 207 207 208 + For CPUs with pointer authentication functionality: 209 + - If EL3 is present: 210 + SCR_EL3.APK (bit 16) must be initialised to 0b1 211 + SCR_EL3.API (bit 17) must be initialised to 0b1 212 + - If the kernel is entered at EL1: 213 + HCR_EL2.APK (bit 40) must be initialised to 0b1 214 + HCR_EL2.API (bit 41) must be initialised to 0b1 215 + 208 216 The requirements described above for CPU mode, caches, MMUs, architected 209 217 timers, coherency and system registers apply to all CPUs. All CPUs must 210 218 enter the kernel in the same exception level.
+8
Documentation/arm64/cpu-feature-registers.txt
··· 184 184 x--------------------------------------------------x 185 185 | Name | bits | visible | 186 186 |--------------------------------------------------| 187 + | GPI | [31-28] | y | 188 + |--------------------------------------------------| 189 + | GPA | [27-24] | y | 190 + |--------------------------------------------------| 187 191 | LRCPC | [23-20] | y | 188 192 |--------------------------------------------------| 189 193 | FCMA | [19-16] | y | 190 194 |--------------------------------------------------| 191 195 | JSCVT | [15-12] | y | 196 + |--------------------------------------------------| 197 + | API | [11-8] | y | 198 + |--------------------------------------------------| 199 + | APA | [7-4] | y | 192 200 |--------------------------------------------------| 193 201 | DPB | [3-0] | y | 194 202 x--------------------------------------------------x
+12
Documentation/arm64/elf_hwcaps.txt
··· 182 182 HWCAP_SSBS 183 183 184 184 Functionality implied by ID_AA64PFR1_EL1.SSBS == 0b0010. 185 + 186 + HWCAP_PACA 187 + 188 + Functionality implied by ID_AA64ISAR1_EL1.APA == 0b0001 or 189 + ID_AA64ISAR1_EL1.API == 0b0001, as described by 190 + Documentation/arm64/pointer-authentication.txt. 191 + 192 + HWCAP_PACG 193 + 194 + Functionality implied by ID_AA64ISAR1_EL1.GPA == 0b0001 or 195 + ID_AA64ISAR1_EL1.GPI == 0b0001, as described by 196 + Documentation/arm64/pointer-authentication.txt.
+88
Documentation/arm64/pointer-authentication.txt
··· 1 + Pointer authentication in AArch64 Linux 2 + ======================================= 3 + 4 + Author: Mark Rutland <mark.rutland@arm.com> 5 + Date: 2017-07-19 6 + 7 + This document briefly describes the provision of pointer authentication 8 + functionality in AArch64 Linux. 9 + 10 + 11 + Architecture overview 12 + --------------------- 13 + 14 + The ARMv8.3 Pointer Authentication extension adds primitives that can be 15 + used to mitigate certain classes of attack where an attacker can corrupt 16 + the contents of some memory (e.g. the stack). 17 + 18 + The extension uses a Pointer Authentication Code (PAC) to determine 19 + whether pointers have been modified unexpectedly. A PAC is derived from 20 + a pointer, another value (such as the stack pointer), and a secret key 21 + held in system registers. 22 + 23 + The extension adds instructions to insert a valid PAC into a pointer, 24 + and to verify/remove the PAC from a pointer. The PAC occupies a number 25 + of high-order bits of the pointer, which varies dependent on the 26 + configured virtual address size and whether pointer tagging is in use. 27 + 28 + A subset of these instructions have been allocated from the HINT 29 + encoding space. In the absence of the extension (or when disabled), 30 + these instructions behave as NOPs. Applications and libraries using 31 + these instructions operate correctly regardless of the presence of the 32 + extension. 33 + 34 + The extension provides five separate keys to generate PACs - two for 35 + instruction addresses (APIAKey, APIBKey), two for data addresses 36 + (APDAKey, APDBKey), and one for generic authentication (APGAKey). 37 + 38 + 39 + Basic support 40 + ------------- 41 + 42 + When CONFIG_ARM64_PTR_AUTH is selected, and relevant HW support is 43 + present, the kernel will assign random key values to each process at 44 + exec*() time. The keys are shared by all threads within the process, and 45 + are preserved across fork(). 46 + 47 + Presence of address authentication functionality is advertised via 48 + HWCAP_PACA, and generic authentication functionality via HWCAP_PACG. 49 + 50 + The number of bits that the PAC occupies in a pointer is 55 minus the 51 + virtual address size configured by the kernel. For example, with a 52 + virtual address size of 48, the PAC is 7 bits wide. 53 + 54 + Recent versions of GCC can compile code with APIAKey-based return 55 + address protection when passed the -msign-return-address option. This 56 + uses instructions in the HINT space (unless -march=armv8.3-a or higher 57 + is also passed), and such code can run on systems without the pointer 58 + authentication extension. 59 + 60 + In addition to exec(), keys can also be reinitialized to random values 61 + using the PR_PAC_RESET_KEYS prctl. A bitmask of PR_PAC_APIAKEY, 62 + PR_PAC_APIBKEY, PR_PAC_APDAKEY, PR_PAC_APDBKEY and PR_PAC_APGAKEY 63 + specifies which keys are to be reinitialized; specifying 0 means "all 64 + keys". 65 + 66 + 67 + Debugging 68 + --------- 69 + 70 + When CONFIG_ARM64_PTR_AUTH is selected, and HW support for address 71 + authentication is present, the kernel will expose the position of TTBR0 72 + PAC bits in the NT_ARM_PAC_MASK regset (struct user_pac_mask), which 73 + userspace can acquire via PTRACE_GETREGSET. 74 + 75 + The regset is exposed only when HWCAP_PACA is set. Separate masks are 76 + exposed for data pointers and instruction pointers, as the set of PAC 77 + bits can vary between the two. Note that the masks apply to TTBR0 78 + addresses, and are not valid to apply to TTBR1 addresses (e.g. kernel 79 + pointers). 80 + 81 + 82 + Virtualization 83 + -------------- 84 + 85 + Pointer authentication is not currently supported in KVM guests. KVM 86 + will mask the feature bits from ID_AA64ISAR1_EL1, and attempted use of 87 + the feature will result in an UNDEFINED exception being injected into 88 + the guest.