From: Amit Daniel Kachhap <amit.kachhap@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
Kees Cook <keescook@chromium.org>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Will Deacon <will.deacon@arm.com>,
Kristina Martsenko <kristina.martsenko@arm.com>,
James Morse <james.morse@arm.com>,
Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>,
Amit Daniel Kachhap <amit.kachhap@arm.com>,
Vincenzo Frascino <Vincenzo.Frascino@arm.com>,
Dave Martin <Dave.Martin@arm.com>
Subject: [PATCH v2 05/14] arm64: enable ptrauth earlier
Date: Tue, 19 Nov 2019 18:02:17 +0530 [thread overview]
Message-ID: <1574166746-27197-6-git-send-email-amit.kachhap@arm.com> (raw)
In-Reply-To: <1574166746-27197-1-git-send-email-amit.kachhap@arm.com>
From: Kristina Martsenko <kristina.martsenko@arm.com>
When the kernel is compiled with pointer auth instructions, the boot CPU
needs to start using address auth very early, so change the cpucap to
account for this.
Pointer auth must be enabled before we call C functions, because it is
not possible to enter a function with pointer auth disabled and exit it
with pointer auth enabled. Note, mismatches between architected and
IMPDEF algorithms will still be caught by the cpufeature framework (the
separate *_ARCH and *_IMP_DEF cpucaps).
Note the change in behavior: if the boot CPU has address auth and a late
CPU does not, then we park the late CPU very early in booting. Also, if
the boot CPU does not have address auth and the late CPU has then system
panic will occur little later from inside the C code. Until now we would
have just disabled address auth in this case.
Leave generic authentication as a "system scope" cpucap for now, since
initially the kernel will only use address authentication.
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
[Amit: Re-worked ptrauth setup logic, comments]
Signed-off-by: Amit Daniel Kachhap <amit.kachhap@arm.com>
---
Changes since last version:
* Added a check __cpu_secondary_checkptrauth for secondary cores which do
not have ptrauth. [James]
* Moved ptrauth setup inside __cpu_setup. [James]
* Now if secondary cpus do not have ptrauth and primary has then this
will cause system panic. [Suzuki]
Link to above discussions: https://www.spinics.net/lists/arm-kernel/msg761993.html
arch/arm64/Kconfig | 5 +++++
arch/arm64/include/asm/smp.h | 1 +
arch/arm64/kernel/cpufeature.c | 13 +++----------
arch/arm64/kernel/head.S | 20 ++++++++++++++++++++
arch/arm64/kernel/smp.c | 2 ++
arch/arm64/mm/proc.S | 31 +++++++++++++++++++++++++++++++
6 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 3f047af..998248e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1436,6 +1436,11 @@ config ARM64_PTR_AUTH
be enabled. However, KVM guest also require VHE mode and hence
CONFIG_ARM64_VHE=y option to use this feature.
+ If the feature is present on the primary CPU but not a secondary CPU,
+ then the secondary CPU will be parked. Also, if the boot CPU does not
+ have address auth and the late CPU has then system panic will occur.
+ On such a system, this option should not be selected.
+
endmenu
config ARM64_SVE
diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index 008d004..ddb6d70 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -22,6 +22,7 @@
#define CPU_STUCK_REASON_52_BIT_VA (UL(1) << CPU_STUCK_REASON_SHIFT)
#define CPU_STUCK_REASON_NO_GRAN (UL(2) << CPU_STUCK_REASON_SHIFT)
+#define CPU_STUCK_REASON_NO_PTRAUTH (UL(4) << CPU_STUCK_REASON_SHIFT)
/* Options for __cpu_setup */
#define ARM64_CPU_BOOT_PRIMARY (1)
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index b6af43f..c05c36a 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1243,12 +1243,6 @@ static void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused)
#endif /* CONFIG_ARM64_RAS_EXTN */
#ifdef CONFIG_ARM64_PTR_AUTH
-static void cpu_enable_address_auth(struct arm64_cpu_capabilities const *cap)
-{
- sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ENIA | SCTLR_ELx_ENIB |
- SCTLR_ELx_ENDA | SCTLR_ELx_ENDB);
-}
-
static bool has_address_auth(const struct arm64_cpu_capabilities *entry,
int __unused)
{
@@ -1525,7 +1519,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
{
.desc = "Address authentication (architected algorithm)",
.capability = ARM64_HAS_ADDRESS_AUTH_ARCH,
- .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+ .type = ARM64_CPUCAP_SCOPE_BOOT_CPU,
.sys_reg = SYS_ID_AA64ISAR1_EL1,
.sign = FTR_UNSIGNED,
.field_pos = ID_AA64ISAR1_APA_SHIFT,
@@ -1535,7 +1529,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
{
.desc = "Address authentication (IMP DEF algorithm)",
.capability = ARM64_HAS_ADDRESS_AUTH_IMP_DEF,
- .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+ .type = ARM64_CPUCAP_SCOPE_BOOT_CPU,
.sys_reg = SYS_ID_AA64ISAR1_EL1,
.sign = FTR_UNSIGNED,
.field_pos = ID_AA64ISAR1_API_SHIFT,
@@ -1544,9 +1538,8 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
},
{
.capability = ARM64_HAS_ADDRESS_AUTH,
- .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+ .type = ARM64_CPUCAP_SCOPE_BOOT_CPU,
.matches = has_address_auth,
- .cpu_enable = cpu_enable_address_auth,
},
{
.desc = "Generic authentication (architected algorithm)",
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 5aaf1bb..c59c28f 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -13,6 +13,7 @@
#include <linux/init.h>
#include <linux/irqchip/arm-gic-v3.h>
+#include <asm/alternative.h>
#include <asm/assembler.h>
#include <asm/boot.h>
#include <asm/ptrace.h>
@@ -713,6 +714,7 @@ secondary_startup:
* Common entry point for secondary CPUs.
*/
bl __cpu_secondary_check52bitva
+ bl __cpu_secondary_checkptrauth
mov x0, #ARM64_CPU_BOOT_LATE
bl __cpu_setup // initialise processor
adrp x1, swapper_pg_dir
@@ -831,6 +833,24 @@ __no_granule_support:
early_park_cpu CPU_STUCK_REASON_NO_GRAN
ENDPROC(__no_granule_support)
+ENTRY(__cpu_secondary_checkptrauth)
+#ifdef CONFIG_ARM64_PTR_AUTH
+ /* Check if the CPU supports ptrauth */
+ mrs x2, id_aa64isar1_el1
+ ubfx x2, x2, #ID_AA64ISAR1_APA_SHIFT, #8
+ cbnz x2, 1f
+alternative_if ARM64_HAS_ADDRESS_AUTH
+ mov x3, 1
+alternative_else
+ mov x3, 0
+alternative_endif
+ cbz x3, 1f
+ /* Park the mismatched secondary CPU */
+ early_park_cpu CPU_STUCK_REASON_NO_PTRAUTH
+#endif
+1: ret
+ENDPROC(__cpu_secondary_checkptrauth)
+
#ifdef CONFIG_RELOCATABLE
__relocate_kernel:
/*
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index dc9fe87..a6a5f24 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -162,6 +162,8 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
pr_crit("CPU%u: does not support 52-bit VAs\n", cpu);
if (status & CPU_STUCK_REASON_NO_GRAN)
pr_crit("CPU%u: does not support %luK granule \n", cpu, PAGE_SIZE / SZ_1K);
+ if (status & CPU_STUCK_REASON_NO_PTRAUTH)
+ pr_crit("CPU%u: does not support pointer authentication\n", cpu);
cpus_stuck_in_kernel++;
break;
case CPU_PANIC_KERNEL:
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 88cf7e4..8734d99 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -16,6 +16,7 @@
#include <asm/pgtable-hwdef.h>
#include <asm/cpufeature.h>
#include <asm/alternative.h>
+#include <asm/smp.h>
#ifdef CONFIG_ARM64_64K_PAGES
#define TCR_TG_FLAGS TCR_TG0_64K | TCR_TG1_64K
@@ -474,9 +475,39 @@ ENTRY(__cpu_setup)
1:
#endif /* CONFIG_ARM64_HW_AFDBM */
msr tcr_el1, x10
+ mov x1, x0
/*
* Prepare SCTLR
*/
mov_q x0, SCTLR_EL1_SET
+
+#ifdef CONFIG_ARM64_PTR_AUTH
+ /* No ptrauth setup for run time cpus */
+ cmp x1, #ARM64_CPU_RUNTIME
+ b.eq 3f
+
+ /* Check if the CPU supports ptrauth */
+ mrs x2, id_aa64isar1_el1
+ ubfx x2, x2, #ID_AA64ISAR1_APA_SHIFT, #8
+ cbz x2, 3f
+
+ msr_s SYS_APIAKEYLO_EL1, xzr
+ msr_s SYS_APIAKEYHI_EL1, xzr
+
+ /* Just enable ptrauth for primary cpu */
+ cmp x1, #ARM64_CPU_BOOT_PRIMARY
+ b.eq 2f
+
+ /* if !system_supports_address_auth() then skip enable */
+alternative_if_not ARM64_HAS_ADDRESS_AUTH
+ b 3f
+alternative_else_nop_endif
+
+2: /* Enable ptrauth instructions */
+ ldr x2, =SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \
+ SCTLR_ELx_ENDA | SCTLR_ELx_ENDB
+ orr x0, x0, x2
+3:
+#endif
ret // return to head.S
ENDPROC(__cpu_setup)
--
2.7.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-11-19 12:34 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-19 12:32 [PATCH v2 00/14] arm64: return address signing Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 01/14] arm64: cpufeature: add pointer auth meta-capabilities Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 02/14] arm64: install user ptrauth keys at kernel exit time Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 03/14] arm64: create macro to park cpu in an infinite loop Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 04/14] arm64: ptrauth: Add bootup/runtime flags for __cpu_setup Amit Daniel Kachhap
2019-11-19 12:32 ` Amit Daniel Kachhap [this message]
2019-11-19 12:32 ` [PATCH v2 06/14] arm64: rename ptrauth key structures to be user-specific Amit Daniel Kachhap
2019-11-22 13:28 ` Ard Biesheuvel
2019-11-25 9:22 ` Amit Kachhap
2019-11-19 12:32 ` [PATCH v2 07/14] arm64: initialize and switch ptrauth kernel keys Amit Daniel Kachhap
2019-11-22 19:19 ` Richard Henderson
2019-11-25 9:34 ` Amit Kachhap
2019-11-25 9:39 ` Ard Biesheuvel
2019-11-25 11:01 ` Amit Kachhap
2019-11-19 12:32 ` [PATCH v2 08/14] arm64: mask PAC bits of __builtin_return_address Amit Daniel Kachhap
2019-11-21 17:42 ` Ard Biesheuvel
2019-11-22 8:48 ` Richard Henderson
2019-11-22 13:27 ` Ard Biesheuvel
2019-11-25 9:18 ` Amit Kachhap
2019-11-25 9:12 ` Amit Kachhap
2019-11-25 5:42 ` Amit Kachhap
2019-11-19 12:32 ` [PATCH v2 09/14] arm64: unwind: strip PAC from kernel addresses Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 10/14] arm64: __show_regs: strip PAC from lr in printk Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 11/14] arm64: suspend: restore the kernel ptrauth keys Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 12/14] arm64: kprobe: disable probe of ptrauth instruction Amit Daniel Kachhap
2019-11-19 12:32 ` [PATCH v2 13/14] arm64: compile the kernel with ptrauth return address signing Amit Daniel Kachhap
2019-11-21 15:06 ` Mark Brown
2019-11-26 7:00 ` Amit Kachhap
2019-11-25 17:35 ` Mark Brown
2019-11-19 12:32 ` [PATCH v2 14/14] lkdtm: arm64: test kernel pointer authentication Amit Daniel Kachhap
2019-11-21 17:39 ` Ard Biesheuvel
2019-11-22 18:51 ` Richard Henderson
2019-11-25 9:25 ` Amit Kachhap
2019-11-25 5:34 ` Amit Kachhap
2019-11-20 16:05 ` [PATCH v2 00/14] arm64: return address signing Ard Biesheuvel
2019-11-21 12:15 ` Amit Kachhap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1574166746-27197-6-git-send-email-amit.kachhap@arm.com \
--to=amit.kachhap@arm.com \
--cc=Dave.Martin@arm.com \
--cc=Vincenzo.Frascino@arm.com \
--cc=ard.biesheuvel@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=keescook@chromium.org \
--cc=kristina.martsenko@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=ramana.radhakrishnan@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).