arm64: align KPTI interface with x86
Subsystems (2)
cover arm64: align KPTI interface with x86
ARM64 supports KPTI, but is missing some user interface features such as a debugfs entry compared to the x86 implementation.
Add the nopti argument, update the documentation so that ARM64 as well as x86 supports nopti and kpti, and add a debugfs entry to check the status of the kpti on a running machine.
--Mark Langsdorf
PATCH 1/4 arm64: capabilities: add nopti command line argument
The x86 kernel and the documentation use 'nopti' as the kernel command line argument to disable kernel page table isolation, so add nopti to the arm64 kernel for compatibility.
--- Documentation/admin-guide/kernel-parameters.txt | 6 +++--- arch/arm64/kernel/cpufeature.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -3
@@ -3342,8 +3342,8 @@ pt. [PARIDE] See Documentation/blockdev/paride.txt. - pti= [X86_64] Control Page Table Isolation of user and - kernel address spaces. Disabling this feature + pti= [X86_64, ARM64] Control Page Table Isolation of user + and kernel address spaces. Disabling this feature removes hardening, but improves performance of system calls and interrupts.
@@ -3354,7 +3354,7 @@ Not specifying this option is equivalent to pti=auto. - nopti [X86_64] + nopti [X86_64, ARM64] Equivalent to pti=off pty.legacy_count=
arch/arm64/kernel/cpufeature.c +10 -1
@@ -934,10 +934,19 @@ static int __init parse_kpti(char *str)if (ret)return ret; - __kpti_forced = enabled ?1 :-1 ; +if (!__kpti_forced) + __kpti_forced = enabled ?1 :-1 ; return 0; }__setup ("kpti=" , parse_kpti); + +/* for compatibility with documentation and x86 nopti command line arg */ +static int __init force_nokpti (char *arg) +{ + __kpti_forced =-1 ; +return 0 ; +} +early_param ("nopti" , force_nokpti);#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #ifdef CONFIG_ARM64_HW_AFDBM
Signature · 1 line
2.9.5
PATCH 1/4 arm64: capabilities: add nopti command line argument
Hi Mark,
Quoted 24 lines · Mark Langsdorf
The x86 kernel and the documentation use 'nopti' as the kernel command line argument to disable kernel page table isolation, so add nopti to the arm64 kernel for compatibility.
Signed-off-by Mark Langsdorf <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 6 +++--- arch/arm64/kernel/cpufeature.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-)Documentation/admin-guide/kernel-parameters.txt +2
-2@@ -3342,8 +3342,8 @@ pt. [PARIDE] See Documentation/blockdev/paride.txt. - pti= [X86_64] Control Page Table Isolation of user and - kernel address spaces. Disabling this feature + pti= [X86_64, ARM64] Control Page Table Isolation of user + and kernel address spaces. Disabling this feature removes hardening, but improves performance of system calls and interrupts.
...
Quoted 15 lines
Documentation/admin-guide/kernel-parameters.txt +1
-1@@ -3354,7 +3354,7 @@ Not specifying this option is equivalent to pti=auto. - nopti [X86_64] + nopti [X86_64, ARM64] Equivalent to pti=off pty.legacy_count=arch/arm64/kernel/cpufeature.c +0
-0
arch/arm64/kernel/cpufeature.c static int __init parse_kpti(char *str) · line 941
Quoted 9 lines
arch/arm64/kernel/cpufeature.c +2
-1@@ -934,10 +934,19 @@ static int __init parse_kpti(char *str)if (ret)return ret; - __kpti_forced = enabled ?1 :-1 ; +if (!__kpti_forced) + __kpti_forced = enabled ?1 :-1 ;return 0 ; }__setup ("kpti=" , parse_kpti);
The arm64 kernel parameter is named "kpti", while the Documentation update above says "pti". We may want to keep both in sync here.
arch/arm64/kernel/cpufeature.c static int __init parse_kpti(char *str) · line 952
Quoted 12 lines
arch/arm64/kernel/cpufeature.c +8
-0+ +/* for compatibility with documentation and x86 nopti command line arg */ +static int __init force_nokpti (char *arg) +{ + __kpti_forced =-1 ; +return 0 ; +} +early_param ("nopti" , force_nokpti);#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #ifdef CONFIG_ARM64_HW_AFDBM
Suzuki
PATCH 1/4 arm64: capabilities: add nopti command line argument
Quoted 47 lines · Suzuki K Poulose
Hi Mark,
Quoted 24 lines · Mark Langsdorf
The x86 kernel and the documentation use 'nopti' as the kernel command line argument to disable kernel page table isolation, so add nopti to the arm64 kernel for compatibility.
Signed-off-by Mark Langsdorf <[email protected]>---
?Documentation/admin-guide/kernel-parameters.txt|? 6 +++--- ?arch/arm64/kernel/cpufeature.c????????????????? | 11 ++++++++++- ? 2 files changed, 13 insertions(+), 4 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -3342,8 +3342,8 @@????? pt.??????? [PARIDE]
????????????? SeeDocumentation/blockdev/paride.txt.
-??? pti=??????? [X86_64] Control Page Table Isolation of user and -??????????? kernel address spaces.? Disabling this feature +??? pti=??????? [X86_64, ARM64] Control Page Table Isolation of user +??????????? and kernel address spaces.? Disabling this feature ????????????? removes hardening, but improves performance of ????????????? system calls and interrupts....
Quoted 15 lines
Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -3354,7 +3354,7 @@????????????? Not specifying this option is equivalent to pti=auto. -??? nopti??????? [
X86_64]
+??? nopti??????? [X86_64, ARM64]
????????????? Equivalent to pti=off
????? pty.legacy_count=arch/arm64/kernel/cpufeature.c +0
-1@@ -934,10 +934,19 @@ static int __init parse_kpti(char *str) ????? if (ret) ????????? return ret; -??? __kpti_forced = enabled ? 1 : -1;
Quoted 8 lines
arch/arm64/kernel/cpufeature.c static int __init parse_kpti(char *str) · line 940
Quoted 5 lines
arch/arm64/kernel/cpufeature.c +2
-0+??? if (!__kpti_forced) +??????? __kpti_forced = enabled ? 1 : -1; ????? return 0; ? } ? __setup("kpti=", parse_kpti);The arm64 kernel parameter is named "kpti", while the Documentation update above says "pti". We may want to keep both in sync here.
Good point. I think I will add a new kpti entry for ARM64 in kernel-parameters. Then the docs match the code, instead of trying to match the code to the docs.
--Mark Langsdorf
PATCH 2/4 arm64: kdebugfs: create arm64 debugfs directory
In reply to Mark LangsdorfCreate debugfs directory for arm64, like the existing one for x86.
--- arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/kdebugfs.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kdebugfs.c
arch/arm64/kernel/Makefile +2 -1
@@ -18,7 +18,8 @@ arm64-obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ hyp-stub.o psci.o cpu_ops.o insn.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ - smp.o smp_spin_table.o topology.o smccc-call.o + smp.o smp_spin_table.o topology.o smccc-call.o \ + kdebugfs.o extra-$(CONFIG_EFI) := efi-entry.o
arch/arm64/kernel/kdebugfs.c new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Architecture specific debugfs files +* +* Copyright (C) 2018 Red Hat, Inc. +*/ + +#include <linux/debugfs.h> +#include <linux/export.h> +#include <linux/init.h> + +struct dentry *arch_debugfs_dir; +EXPORT_SYMBOL (arch_debugfs_dir); + +static int __init arch_kdebugfs_init (void ) +{ +int error =0 ; + + arch_debugfs_dir =debugfs_create_dir ("arm64" ,NULL ); +if (IS_ERR (arch_debugfs_dir)) { + arch_debugfs_dir =NULL ; +return -ENOMEM ; + } + +return error; +} +postcore_initcall (arch_kdebugfs_init);
Signature · 1 line
2.9.5
PATCH 3/4 arm64: cpufeature: add debugfs interface for KPTI
In reply to Mark LangsdorfAdd a debugfs interface to check if KPTI is enabled or disabled:
cat /sys/kernel/debug/arm64/pti_enabled
Slightly rework unmap_kernel_at_el0 logic to simplify calculating if KPTI is enabled.
--- arch/arm64/kernel/cpufeature.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
arch/arm64/kernel/cpufeature.c +20 -10
@@ -24,6 +24,7 @@#include <linux/stop_machine.h> #include <linux/types.h> #include <linux/mm.h> +#include <linux/debugfs.h> #include <asm/cpu.h> #include <asm/cpufeature.h> #include <asm/cpu_ops.h>
@@ -860,6 +861,7 @@ static bool has_cache_dic(const struct arm64_cpu_capabilities *entry,#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 static int __kpti_forced;/* 0: not forced, >0: forced on, <0: forced off */ +static bool __pti_enabled;static bool unmap_kernel_at_el0 (const struct arm64_cpu_capabilities *entry,int scope)
@@ -884,21 +886,21 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,/* Forced? */ if (__kpti_forced) { + __pti_enabled = __kpti_forced >0 ;pr_info_once ("kernel page table isolation forced %s by %s\n" , - __kpti_forced >0 ?"ON" :"OFF" , str); -return __kpti_forced >0 ; + __pti_enabled ?"ON" :"OFF" , str); } -/* Useful for KASLR robustness */ -if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) -return true; - +else if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) + __pti_enabled = true;/* Don't force KPTI for CPUs that are not vulnerable */ -if (is_midr_in_range_list (read_cpuid_id (), kpti_safe_list)) -return false; - +else if (is_midr_in_range_list (read_cpuid_id (), kpti_safe_list)) + __pti_enabled = false;/* Defer to CPU feature registers */ -return !has_cpuid_feature (entry, scope); +else + __pti_enabled = !has_cpuid_feature (entry, scope); + +return __pti_enabled; } static void
@@ -947,6 +949,14 @@ static int __init force_nokpti(char *arg) return 0; }early_param ("nopti" , force_nokpti); + +static int __init create_kpti_enabled (void ) +{ +debugfs_create_bool ("pti_enabled" ,S_IRUSR , + arch_debugfs_dir, &__pti_enabled); +return 0 ; +} +late_initcall (create_kpti_enabled);#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #ifdef CONFIG_ARM64_HW_AFDBM
Signature · 1 line
2.9.5
PATCH 4/4 arm64: cpufeature: always log KPTI setting on boot
In reply to Mark LangsdorfAlways log KPTI setting at boot time, whether or not KPTI was forced by a kernel parameter.
--- arch/arm64/kernel/cpufeature.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
arch/arm64/kernel/cpufeature.c +13 -9
@@ -889,16 +889,20 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, __pti_enabled = __kpti_forced >0 ;pr_info_once ("kernel page table isolation forced %s by %s\n" , __pti_enabled ?"ON" :"OFF" , str); + }else { +/* Useful for KASLR robustness */ +if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) + __pti_enabled = true; +/* Don't force KPTI for CPUs that are not vulnerable */ +else if (is_midr_in_range_list (read_cpuid_id (), kpti_safe_list)) + __pti_enabled = false; +/* Defer to CPU feature registers */ +else + __pti_enabled = !has_cpuid_feature (entry, scope); + +pr_info_once ("kernel page table isolation %s by %s\n" , + __pti_enabled ?"ON" :"OFF" , str); } -/* Useful for KASLR robustness */ -else if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) - __pti_enabled = true; -/* Don't force KPTI for CPUs that are not vulnerable */ -else if (is_midr_in_range_list (read_cpuid_id (), kpti_safe_list)) - __pti_enabled = false; -/* Defer to CPU feature registers */ -else - __pti_enabled = !has_cpuid_feature (entry, scope);return __pti_enabled; }
Signature · 1 line
2.9.5
PATCH 4/4 arm64: cpufeature: always log KPTI setting on boot
Quoted 19 lines · Mark Langsdorf
Always log KPTI setting at boot time, whether or not KPTI was forced by a kernel parameter.
Signed-off-by Mark Langsdorf <[email protected]>--- arch/arm64/kernel/cpufeature.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)arch/arm64/kernel/cpufeature.c +3
-0@@ -889,16 +889,20 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, __pti_enabled = __kpti_forced >0 ;pr_info_once ("kernel page table isolation forced %s by %s\n" , __pti_enabled ?"ON" :"OFF" , str); + }else { +/* Useful for KASLR robustness */ +if (IS_ENABLED (CONFIG_RANDOMIZE_BASE ))
arch/arm64/kernel/cpufeature.c static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, · line 904
Quoted 10 lines
arch/arm64/kernel/cpufeature.c +10
-0+ __pti_enabled = true; +/* Don't force KPTI for CPUs that are not vulnerable */ + else if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) + __pti_enabled = false; +/* Defer to CPU feature registers */ + else + __pti_enabled = !has_cpuid_feature (entry, scope); + +pr_info_once ("kernel page table isolation %s by %s\n" , + __pti_enabled ?"ON" :"OFF" , str);
I think this needs an update for the default logged, otherwise it incorrectly states it was set by command line:
# dmesg | grep isolation [ 0.000000] CPU features: kernel page table isolation ON by command line option [ 0.000000] CPU features: detected: Kernel page table isolation (KPTI) # cat /proc/cmdline nokaslr slub_debug=- console=ttyAMA0 debug_pagealloc=on earlycon=pl011,0x9000000
Quoted 14 lines
arch/arm64/kernel/cpufeature.c +0
-9} -/* Useful for KASLR robustness */ -else if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) - __pti_enabled = true; -/* Don't force KPTI for CPUs that are not vulnerable */ -else if (is_midr_in_range_list (read_cpuid_id (), kpti_safe_list)) - __pti_enabled = false; -/* Defer to CPU feature registers */ -else - __pti_enabled = !has_cpuid_feature (entry, scope);return __pti_enabled; }
cover arm64: align KPTI interface with x86
In reply to Mark LangsdorfQuoted 2 lines · Mark Langsdorf
ARM64 supports KPTI, but is missing some user interface features such as a debugfs entry compared to the x86 implementation.
I don't see an x86 debugfs entry for PTI, only the sysfs files. Was this something that was discussed bug never merged?
Thanks,
Laura