Skip to content

Commit b8fdef3

Browse files
brooniectmarinas
authored andcommitted
arm64: Always force a branch protection mode when the compiler has one
Compilers with branch protection support can be configured to enable it by default, it is likely that distributions will do this as part of deploying branch protection system wide. As well as the slight overhead from having some extra NOPs for unused branch protection features this can cause more serious problems when the kernel is providing pointer authentication to userspace but not built for pointer authentication itself. In that case our switching of keys for userspace can affect the kernel unexpectedly, causing pointer authentication instructions in the kernel to corrupt addresses. To ensure that we get consistent and reliable behaviour always explicitly initialise the branch protection mode, ensuring that the kernel is built the same way regardless of the compiler defaults. Fixes: 7503197 (arm64: add basic pointer authentication support) Reported-by: Szabolcs Nagy <[email protected]> Signed-off-by: Mark Brown <[email protected]> Cc: [email protected] [[email protected]: remove Kconfig option in favour of Makefile check] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 15cd0e6 commit b8fdef3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/arm64/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ stack_protector_prepare: prepare0
6565
include/generated/asm-offsets.h))
6666
endif
6767

68+
# Ensure that if the compiler supports branch protection we default it
69+
# off, this will be overridden if we are using branch protection.
70+
branch-prot-flags-y += $(call cc-option,-mbranch-protection=none)
71+
6872
ifeq ($(CONFIG_ARM64_PTR_AUTH),y)
6973
branch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all
7074
branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pac-ret+leaf
@@ -73,9 +77,10 @@ branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pa
7377
# we pass it only to the assembler. This option is utilized only in case of non
7478
# integrated assemblers.
7579
branch-prot-flags-$(CONFIG_AS_HAS_PAC) += -Wa,-march=armv8.3-a
76-
KBUILD_CFLAGS += $(branch-prot-flags-y)
7780
endif
7881

82+
KBUILD_CFLAGS += $(branch-prot-flags-y)
83+
7984
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
8085
KBUILD_CPPFLAGS += -mbig-endian
8186
CHECKFLAGS += -D__AARCH64EB__

0 commit comments

Comments
 (0)