History

arm64: Unconditionally enable PAN support

FEAT_PAN has been around since ARMv8.1 (over 11 years ago), has no compiler dependency (we have our own accessors), and is a great security benefit. Drop CONFIG_ARM64_PAN, and make the support unconditionnal.

Marc Zyngier committed 10 months ago

Commit 018a2311 parent 6191b255 files · +3 −28Browse files

Unified · Split

5 files
  1. arch/arm64/Kconfig +0 −17
  2. arch/arm64/include/asm/cpucaps.h +0 −2
  3. arch/arm64/include/asm/uaccess.h +2 −4
  4. arch/arm64/kernel/cpufeature.c +0 −4
  5. arch/arm64/kvm/hyp/entry.S +1 −1
arch/arm64/Kconfig+0−17
@@ -1680,7 +1680,6 @@ config MITIGATE_SPECTRE_BRANCH_HISTORY · 1679 unmodified lines
1680config ARM64_SW_TTBR0_PAN1680config ARM64_SW_TTBR0_PAN
1681 bool "Emulate Privileged Access Never using TTBR0_EL1 switching"1681 bool "Emulate Privileged Access Never using TTBR0_EL1 switching"
1682 depends on !KCSAN1682 depends on !KCSAN
1683 select ARM64_PAN
1684 help1683 help
1685 Enabling this option prevents the kernel from accessing1684 Enabling this option prevents the kernel from accessing
1686 user-space memory directly by pointing TTBR0_EL1 to a reserved1685 user-space memory directly by pointing TTBR0_EL1 to a reserved
@@ -1859,20 +1858,6 @@ config ARM64_HW_AFDBM · 172 unmodified lines
1859 to work on pre-ARMv8.1 hardware and the performance impact is1858 to work on pre-ARMv8.1 hardware and the performance impact is
1860 minimal. If unsure, say Y.1859 minimal. If unsure, say Y.
1861 1860
1862config ARM64_PAN
1863 bool "Enable support for Privileged Access Never (PAN)"
1864 default y
1865 help
1866 Privileged Access Never (PAN; part of the ARMv8.1 Extensions)
1867 prevents the kernel or hypervisor from accessing user-space (EL0)
1868 memory directly.
1869
1870 Choosing this option will cause any unprotected (not using
1871 copy_to_user et al) memory access to fail with a permission fault.
1872
1873 The feature is detected at runtime, and will remain as a 'nop'
1874 instruction if the cpu does not implement the feature.
1875
1876endmenu # "ARMv8.1 architectural features"1861endmenu # "ARMv8.1 architectural features"
1877 1862
1878menu "ARMv8.2 architectural features"1863menu "ARMv8.2 architectural features"
@@ -2109,7 +2094,6 @@ config ARM64_MTE · 230 unmodified lines
2109 depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI2094 depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI
2110 depends on AS_HAS_ARMV8_52095 depends on AS_HAS_ARMV8_5
2111 # Required for tag checking in the uaccess routines2096 # Required for tag checking in the uaccess routines
2112 select ARM64_PAN
2113 select ARCH_HAS_SUBPAGE_FAULTS2097 select ARCH_HAS_SUBPAGE_FAULTS
2114 select ARCH_USES_HIGH_VMA_FLAGS2098 select ARCH_USES_HIGH_VMA_FLAGS
2115 select ARCH_USES_PG_ARCH_22099 select ARCH_USES_PG_ARCH_2
@@ -2141,7 +2125,6 @@ menu "ARMv8.7 architectural features" · 25 unmodified lines
2141config ARM64_EPAN2125config ARM64_EPAN
2142 bool "Enable support for Enhanced Privileged Access Never (EPAN)"2126 bool "Enable support for Enhanced Privileged Access Never (EPAN)"
2143 default y2127 default y
2144 depends on ARM64_PAN
2145 help2128 help
2146 Enhanced Privileged Access Never (EPAN) allows Privileged2129 Enhanced Privileged Access Never (EPAN) allows Privileged
2147 Access Never to be used with Execute-only mappings.2130 Access Never to be used with Execute-only mappings.
arch/arm64/include/asm/cpucaps.h+0−2
@@ -19,8 +19,6 @@ cpucap_is_possible(const unsigned int cap) · 18 unmodified lines
19 "cap must be < ARM64_NCAPS");19 "cap must be < ARM64_NCAPS");
20 20
21 switch (cap) {21 switch (cap) {
22 case ARM64_HAS_PAN:
23 return IS_ENABLED(CONFIG_ARM64_PAN);
24 case ARM64_HAS_EPAN:22 case ARM64_HAS_EPAN:
25 return IS_ENABLED(CONFIG_ARM64_EPAN);23 return IS_ENABLED(CONFIG_ARM64_EPAN);
26 case ARM64_SVE:24 case ARM64_SVE:
arch/arm64/include/asm/uaccess.h+2−4
@@ -124,14 +124,12 @@ static inline bool uaccess_ttbr0_enable(void) · 123 unmodified lines
124 124
125static inline void __uaccess_disable_hw_pan(void)125static inline void __uaccess_disable_hw_pan(void)
126{126{
127 asm(ALTERNATIVE("nop", SET_PSTATE_PAN(0), ARM64_HAS_PAN,127 asm(ALTERNATIVE("nop", SET_PSTATE_PAN(0), ARM64_HAS_PAN));
128 CONFIG_ARM64_PAN));
129}128}
130 129
131static inline void __uaccess_enable_hw_pan(void)130static inline void __uaccess_enable_hw_pan(void)
132{131{
133 asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,132 asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN));
134 CONFIG_ARM64_PAN));
135}133}
136 134
137static inline void uaccess_disable_privileged(void)135static inline void uaccess_disable_privileged(void)
arch/arm64/kernel/cpufeature.c+0−4
@@ -2164,7 +2164,6 @@ static bool has_bbml2_noabort(const struct arm64_cpu_capabilities *caps, int sco · 2163 unmodified lines
2164 return cpu_supports_bbml2_noabort();2164 return cpu_supports_bbml2_noabort();
2165}2165}
2166 2166
2167#ifdef CONFIG_ARM64_PAN
2168static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)2167static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
2169{2168{
2170 /*2169 /*
@@ -2176,7 +2175,6 @@ static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) · 5 unmodified lines
2176 sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);2175 sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);
2177 set_pstate_pan(1);2176 set_pstate_pan(1);
2178}2177}
2179#endif /* CONFIG_ARM64_PAN */
2180 2178
2181#ifdef CONFIG_ARM64_RAS_EXTN2179#ifdef CONFIG_ARM64_RAS_EXTN
2182static void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused)2180static void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused)
@@ -2541,7 +2539,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { · 358 unmodified lines
2541 .matches = has_cpuid_feature,2539 .matches = has_cpuid_feature,
2542 ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, ECV, CNTPOFF)2540 ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, ECV, CNTPOFF)
2543 },2541 },
2544#ifdef CONFIG_ARM64_PAN
2545 {2542 {
2546 .desc = "Privileged Access Never",2543 .desc = "Privileged Access Never",
2547 .capability = ARM64_HAS_PAN,2544 .capability = ARM64_HAS_PAN,
@@ -2550,7 +2547,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { · 2 unmodified lines
2550 .cpu_enable = cpu_enable_pan,2547 .cpu_enable = cpu_enable_pan,
2551 ARM64_CPUID_FIELDS(ID_AA64MMFR1_EL1, PAN, IMP)2548 ARM64_CPUID_FIELDS(ID_AA64MMFR1_EL1, PAN, IMP)
2552 },2549 },
2553#endif /* CONFIG_ARM64_PAN */
2554#ifdef CONFIG_ARM64_EPAN2550#ifdef CONFIG_ARM64_EPAN
2555 {2551 {
2556 .desc = "Enhanced Privileged Access Never",2552 .desc = "Enhanced Privileged Access Never",
arch/arm64/kvm/hyp/entry.S+1−1
@@ -126,7 +126,7 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) · 125 unmodified lines
126 126
127 add x1, x1, #VCPU_CONTEXT127 add x1, x1, #VCPU_CONTEXT
128 128
129 ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN, CONFIG_ARM64_PAN)129 ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN)
130 130
131 // Store the guest regs x2 and x3131 // Store the guest regs x2 and x3
132 stp x2, x3, [x1, #CPU_XREG_OFFSET(2)]132 stp x2, x3, [x1, #CPU_XREG_OFFSET(2)]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t