Skip to content

Commit c835578

Browse files
committed
arm64: kpti: Fix "kpti=off" when KASLR is enabled
Enabling KASLR forces the use of non-global page-table entries for kernel mappings, as this is a decision that we have to make very early on before mapping the kernel proper. When used in conjunction with the "kpti=off" command-line option, it is possible to use non-global kernel mappings but with the kpti trampoline disabled. Since commit 09e3c22 ("arm64: Use a variable to store non-global mappings decision"), arm64_kernel_unmapped_at_el0() reflects only the use of non-global mappings and does not take into account whether the kpti trampoline is enabled. This breaks context switching of the TPIDRRO_EL0 register for 64-bit tasks, where the clearing of the register is deferred to the ret-to-user code, but it also breaks the ARM SPE PMU driver which helpfully recommends passing "kpti=off" on the command line! Report whether or not KPTI is actually enabled in arm64_kernel_unmapped_at_el0() and check the 'arm64_use_ng_mappings' global variable directly when determining the protection flags for kernel mappings. Cc: Mark Brown <[email protected]> Reported-by: Hongbo Yao <[email protected]> Tested-by: Hongbo Yao <[email protected]> Fixes: 09e3c22 ("arm64: Use a variable to store non-global mappings decision") Signed-off-by: Will Deacon <[email protected]>
1 parent f50b7da commit c835578

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

arch/arm64/include/asm/mmu.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ typedef struct {
2929
*/
3030
#define ASID(mm) ((mm)->context.id.counter & 0xffff)
3131

32-
extern bool arm64_use_ng_mappings;
33-
3432
static inline bool arm64_kernel_unmapped_at_el0(void)
3533
{
36-
return arm64_use_ng_mappings;
34+
return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
3735
}
3836

3937
typedef void (*bp_hardening_cb_t)(void);

arch/arm64/include/asm/pgtable-prot.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
#include <asm/pgtable-types.h>
2525

26+
extern bool arm64_use_ng_mappings;
27+
2628
#define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
2729
#define _PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
2830

29-
#define PTE_MAYBE_NG (arm64_kernel_unmapped_at_el0() ? PTE_NG : 0)
30-
#define PMD_MAYBE_NG (arm64_kernel_unmapped_at_el0() ? PMD_SECT_NG : 0)
31+
#define PTE_MAYBE_NG (arm64_use_ng_mappings ? PTE_NG : 0)
32+
#define PMD_MAYBE_NG (arm64_use_ng_mappings ? PMD_SECT_NG : 0)
3133

3234
#define PROT_DEFAULT (_PROT_DEFAULT | PTE_MAYBE_NG)
3335
#define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_MAYBE_NG)

0 commit comments

Comments
 (0)