Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v5.2-rc2 107 lines 4.6 kB view raw
1Pointer authentication in AArch64 Linux 2======================================= 3 4Author: Mark Rutland <mark.rutland@arm.com> 5Date: 2017-07-19 6 7This document briefly describes the provision of pointer authentication 8functionality in AArch64 Linux. 9 10 11Architecture overview 12--------------------- 13 14The ARMv8.3 Pointer Authentication extension adds primitives that can be 15used to mitigate certain classes of attack where an attacker can corrupt 16the contents of some memory (e.g. the stack). 17 18The extension uses a Pointer Authentication Code (PAC) to determine 19whether pointers have been modified unexpectedly. A PAC is derived from 20a pointer, another value (such as the stack pointer), and a secret key 21held in system registers. 22 23The extension adds instructions to insert a valid PAC into a pointer, 24and to verify/remove the PAC from a pointer. The PAC occupies a number 25of high-order bits of the pointer, which varies dependent on the 26configured virtual address size and whether pointer tagging is in use. 27 28A subset of these instructions have been allocated from the HINT 29encoding space. In the absence of the extension (or when disabled), 30these instructions behave as NOPs. Applications and libraries using 31these instructions operate correctly regardless of the presence of the 32extension. 33 34The extension provides five separate keys to generate PACs - two for 35instruction addresses (APIAKey, APIBKey), two for data addresses 36(APDAKey, APDBKey), and one for generic authentication (APGAKey). 37 38 39Basic support 40------------- 41 42When CONFIG_ARM64_PTR_AUTH is selected, and relevant HW support is 43present, the kernel will assign random key values to each process at 44exec*() time. The keys are shared by all threads within the process, and 45are preserved across fork(). 46 47Presence of address authentication functionality is advertised via 48HWCAP_PACA, and generic authentication functionality via HWCAP_PACG. 49 50The number of bits that the PAC occupies in a pointer is 55 minus the 51virtual address size configured by the kernel. For example, with a 52virtual address size of 48, the PAC is 7 bits wide. 53 54Recent versions of GCC can compile code with APIAKey-based return 55address protection when passed the -msign-return-address option. This 56uses instructions in the HINT space (unless -march=armv8.3-a or higher 57is also passed), and such code can run on systems without the pointer 58authentication extension. 59 60In addition to exec(), keys can also be reinitialized to random values 61using the PR_PAC_RESET_KEYS prctl. A bitmask of PR_PAC_APIAKEY, 62PR_PAC_APIBKEY, PR_PAC_APDAKEY, PR_PAC_APDBKEY and PR_PAC_APGAKEY 63specifies which keys are to be reinitialized; specifying 0 means "all 64keys". 65 66 67Debugging 68--------- 69 70When CONFIG_ARM64_PTR_AUTH is selected, and HW support for address 71authentication is present, the kernel will expose the position of TTBR0 72PAC bits in the NT_ARM_PAC_MASK regset (struct user_pac_mask), which 73userspace can acquire via PTRACE_GETREGSET. 74 75The regset is exposed only when HWCAP_PACA is set. Separate masks are 76exposed for data pointers and instruction pointers, as the set of PAC 77bits can vary between the two. Note that the masks apply to TTBR0 78addresses, and are not valid to apply to TTBR1 addresses (e.g. kernel 79pointers). 80 81Additionally, when CONFIG_CHECKPOINT_RESTORE is also set, the kernel 82will expose the NT_ARM_PACA_KEYS and NT_ARM_PACG_KEYS regsets (struct 83user_pac_address_keys and struct user_pac_generic_keys). These can be 84used to get and set the keys for a thread. 85 86 87Virtualization 88-------------- 89 90Pointer authentication is enabled in KVM guest when each virtual cpu is 91initialised by passing flags KVM_ARM_VCPU_PTRAUTH_[ADDRESS/GENERIC] and 92requesting these two separate cpu features to be enabled. The current KVM 93guest implementation works by enabling both features together, so both 94these userspace flags are checked before enabling pointer authentication. 95The separate userspace flag will allow to have no userspace ABI changes 96if support is added in the future to allow these two features to be 97enabled independently of one another. 98 99As Arm Architecture specifies that Pointer Authentication feature is 100implemented along with the VHE feature so KVM arm64 ptrauth code relies 101on VHE mode to be present. 102 103Additionally, when these vcpu feature flags are not set then KVM will 104filter out the Pointer Authentication system key registers from 105KVM_GET/SET_REG_* ioctls and mask those features from cpufeature ID 106register. Any attempt to use the Pointer Authentication instructions will 107result in an UNDEFINED exception being injected into the guest.