arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS)
authorPeter Collingbourne <pcc@google.com>
Fri, 19 Mar 2021 03:10:53 +0000 (20:10 -0700)
committerCatalin Marinas <catalin.marinas@arm.com>
Tue, 13 Apr 2021 16:31:44 +0000 (17:31 +0100)
commit201698626fbca1cf1a3b686ba14cf2a056500716
tree84e0f6591d4d0f3ea2052cc36ad797194f071b44
parent2f79d2fc391e4ba64df908b8c07dda6c3a907056
arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS)

This change introduces a prctl that allows the user program to control
which PAC keys are enabled in a particular task. The main reason
why this is useful is to enable a userspace ABI that uses PAC to
sign and authenticate function pointers and other pointers exposed
outside of the function, while still allowing binaries conforming
to the ABI to interoperate with legacy binaries that do not sign or
authenticate pointers.

The idea is that a dynamic loader or early startup code would issue
this prctl very early after establishing that a process may load legacy
binaries, but before executing any PAC instructions.

This change adds a small amount of overhead to kernel entry and exit
due to additional required instruction sequences.

On a DragonBoard 845c (Cortex-A75) with the powersave governor, the
overhead of similar instruction sequences was measured as 4.9ns when
simulating the common case where IA is left enabled, or 43.7ns when
simulating the uncommon case where IA is disabled. These numbers can
be seen as the worst case scenario, since in more realistic scenarios
a better performing governor would be used and a newer chip would be
used that would support PAC unlike Cortex-A75 and would be expected
to be faster than Cortex-A75.

On an Apple M1 under a hypervisor, the overhead of the entry/exit
instruction sequences introduced by this patch was measured as 0.3ns
in the case where IA is left enabled, and 33.0ns in the case where
IA is disabled.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Reviewed-by: Dave Martin <Dave.Martin@arm.com>
Link: https://linux-review.googlesource.com/id/Ibc41a5e6a76b275efbaa126b31119dc197b927a5
Link: https://lore.kernel.org/r/d6609065f8f40397a4124654eb68c9f490b4d477.1616123271.git.pcc@google.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
14 files changed:
Documentation/arm64/pointer-authentication.rst
arch/arm64/include/asm/mte.h
arch/arm64/include/asm/pointer_auth.h
arch/arm64/include/asm/processor.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kernel/asm-offsets.c
arch/arm64/kernel/entry.S
arch/arm64/kernel/mte.c
arch/arm64/kernel/pointer_auth.c
arch/arm64/kernel/process.c
arch/arm64/kernel/ptrace.c
include/uapi/linux/elf.h
include/uapi/linux/prctl.h
kernel/sys.c