Commit 2cd5e79f authored by Kristina Martšenko's avatar Kristina Martšenko
Browse files

arm64: compile the kernel with ptrauth return address signing

Compile all non-leaf functions with two ptrauth instructions: PACIASP in
the prologue to sign the return address, and AUTIASP in the epilogue to
authenticate the return address (from the stack). If authentication
fails, the return will cause an instruction abort to be taken, followed
by an oops and killing the task.

This should help protect the kernel against attacks using
return-oriented programming. As ptrauth protects the return address, it
can also serve as a replacement for CONFIG_STACKPROTECTOR, although note
that it does not protect other parts of the stack.

The new instructions are in the HINT encoding space, so on a system
without ptrauth they execute as NOPs.

CONFIG_ARM64_PTR_AUTH now not only enables ptrauth for userspace and KVM
guests, but also automatically builds the kernel with ptrauth
instructions if the compiler supports it. If there is no compiler
support, we do not warn that the kernel was built without ptrauth

GCC 7 and 8 support the -msign-return-address option, while GCC 9
deprecates that option and replaces it with -mbranch-protection. Support
both options.
Reviewed-by: default avatarKees Cook <>
Signed-off-by: default avatarKristina Martšenko <>
parent c5b5749a
......@@ -1367,11 +1367,17 @@ config ARM64_PTR_AUTH
and other attacks.
This option enables these instructions at EL0 (i.e. for userspace).
Choosing this option will cause the kernel to initialise secret keys
for each process at exec() time, with these keys being
context-switched along with the process.
If the compiler supports the -mbranch-protection or
-msign-return-address flag (e.g. GCC 7 or later), then this option
will also cause the kernel itself to be compiled with return address
protection. In this case, and if the target hardware is known to
support pointer authentication, then CONFIG_STACKPROTECTOR can be
disabled with minimal loss of protection.
The feature is detected at runtime. If the feature is not present in
hardware it will not be advertised to userspace/KVM guest nor will it
be enabled. However, KVM guest also require VHE mode and hence
......@@ -1381,6 +1387,14 @@ config ARM64_PTR_AUTH
then the secondary CPU will be offlined. On such a system, this
option should not be selected.
# GCC 9 or later
def_bool $(cc-option,-mbranch-protection=pac-ret)
# GCC 7, 8
def_bool $(cc-option,-msign-return-address=non-leaf)
config ARM64_SVE
......@@ -67,6 +67,12 @@ stack_protector_prepare: prepare0
ifeq ($(CONFIG_ARM64_PTR_AUTH),y)
pac-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=non-leaf
pac-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pac-ret
KBUILD_CFLAGS += $(pac-flags-y)
KBUILD_CPPFLAGS += -mbig-endian
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment