Skip to content

Commit b27a9f4

Browse files
DanielKristofKisswilldeacon
authored andcommitted
arm64: Add ARM64_PTR_AUTH_KERNEL config option
This patch add the ARM64_PTR_AUTH_KERNEL config and deals with the build aspect of it. Userspace support has no dependency on the toolchain therefore all toolchain checks and build flags are controlled the new config option. The default config behavior will not be changed. Signed-off-by: Daniel Kiss <daniel.kiss@arm.com> Acked-by: Will Deacon <will@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/20210613092632.93591-2-daniel.kiss@arm.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent c468154 commit b27a9f4

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

arch/arm64/Kconfig

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,12 +1481,6 @@ menu "ARMv8.3 architectural features"
14811481
config ARM64_PTR_AUTH
14821482
bool "Enable support for pointer authentication"
14831483
default y
1484-
depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC
1485-
# Modern compilers insert a .note.gnu.property section note for PAC
1486-
# which is only understood by binutils starting with version 2.33.1.
1487-
depends on LD_IS_LLD || LD_VERSION >= 23301 || (CC_IS_GCC && GCC_VERSION < 90100)
1488-
depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE
1489-
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
14901484
help
14911485
Pointer authentication (part of the ARMv8.3 Extensions) provides
14921486
instructions for signing and authenticating pointers against secret
@@ -1498,13 +1492,6 @@ config ARM64_PTR_AUTH
14981492
for each process at exec() time, with these keys being
14991493
context-switched along with the process.
15001494

1501-
If the compiler supports the -mbranch-protection or
1502-
-msign-return-address flag (e.g. GCC 7 or later), then this option
1503-
will also cause the kernel itself to be compiled with return address
1504-
protection. In this case, and if the target hardware is known to
1505-
support pointer authentication, then CONFIG_STACKPROTECTOR can be
1506-
disabled with minimal loss of protection.
1507-
15081495
The feature is detected at runtime. If the feature is not present in
15091496
hardware it will not be advertised to userspace/KVM guest nor will it
15101497
be enabled.
@@ -1515,6 +1502,24 @@ config ARM64_PTR_AUTH
15151502
but with the feature disabled. On such a system, this option should
15161503
not be selected.
15171504

1505+
config ARM64_PTR_AUTH_KERNEL
1506+
bool
1507+
default y
1508+
depends on ARM64_PTR_AUTH
1509+
depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC
1510+
# Modern compilers insert a .note.gnu.property section note for PAC
1511+
# which is only understood by binutils starting with version 2.33.1.
1512+
depends on LD_IS_LLD || LD_VERSION >= 23301 || (CC_IS_GCC && GCC_VERSION < 90100)
1513+
depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE
1514+
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
1515+
help
1516+
If the compiler supports the -mbranch-protection or
1517+
-msign-return-address flag (e.g. GCC 7 or later), then this option
1518+
will cause the kernel itself to be compiled with return address
1519+
protection. In this case, and if the target hardware is known to
1520+
support pointer authentication, then CONFIG_STACKPROTECTOR can be
1521+
disabled with minimal loss of protection.
1522+
15181523
This feature works with FUNCTION_GRAPH_TRACER option only if
15191524
DYNAMIC_FTRACE_WITH_REGS is enabled.
15201525

@@ -1606,7 +1611,7 @@ config ARM64_BTI_KERNEL
16061611
bool "Use Branch Target Identification for kernel"
16071612
default y
16081613
depends on ARM64_BTI
1609-
depends on ARM64_PTR_AUTH
1614+
depends on ARM64_PTR_AUTH_KERNEL
16101615
depends on CC_HAS_BRANCH_PROT_PAC_RET_BTI
16111616
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94697
16121617
depends on !CC_IS_GCC || GCC_VERSION >= 100100

arch/arm64/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ endif
7070
# off, this will be overridden if we are using branch protection.
7171
branch-prot-flags-y += $(call cc-option,-mbranch-protection=none)
7272

73-
ifeq ($(CONFIG_ARM64_PTR_AUTH),y)
73+
ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
7474
branch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all
7575
# We enable additional protection for leaf functions as there is some
7676
# narrow potential for ROP protection benefits and no substantial

arch/arm64/kernel/asm-offsets.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ int main(void)
4646
DEFINE(THREAD_SCTLR_USER, offsetof(struct task_struct, thread.sctlr_user));
4747
#ifdef CONFIG_ARM64_PTR_AUTH
4848
DEFINE(THREAD_KEYS_USER, offsetof(struct task_struct, thread.keys_user));
49+
#endif
50+
#ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
4951
DEFINE(THREAD_KEYS_KERNEL, offsetof(struct task_struct, thread.keys_kernel));
5052
#endif
5153
#ifdef CONFIG_ARM64_MTE

drivers/misc/lkdtm/bugs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void lkdtm_DOUBLE_FAULT(void)
463463
#ifdef CONFIG_ARM64
464464
static noinline void change_pac_parameters(void)
465465
{
466-
if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH)) {
466+
if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL)) {
467467
/* Reset the keys of current task */
468468
ptrauth_thread_init_kernel(current);
469469
ptrauth_thread_switch_kernel(current);
@@ -477,8 +477,8 @@ noinline void lkdtm_CORRUPT_PAC(void)
477477
#define CORRUPT_PAC_ITERATE 10
478478
int i;
479479

480-
if (!IS_ENABLED(CONFIG_ARM64_PTR_AUTH))
481-
pr_err("FAIL: kernel not built with CONFIG_ARM64_PTR_AUTH\n");
480+
if (!IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL))
481+
pr_err("FAIL: kernel not built with CONFIG_ARM64_PTR_AUTH_KERNEL\n");
482482

483483
if (!system_supports_address_auth()) {
484484
pr_err("FAIL: CPU lacks pointer authentication feature\n");

0 commit comments

Comments
 (0)