arm64: set UXN on swapper page tables
Subsystems (2)
PATCH 1/1 arm64: set UXN on swapper page tables
On a system that implements FEAT_EPAN, read/write access to the idmap is denied because UXN is not set on the swapper PTEs. As a result, idmap_kpti_install_ng_mappings panics the kernel when accessing __idmap_kpti_flag. Fix it by setting UXN on these PTEs.
---
This fix is no longer needed since commit c3cee924bd85 ("arm64: head:
cover entire kernel image in initial ID map"), which moved __idmap_kpti_flag to .data, but that commit is currently only present in next.
arch/arm64/include/asm/kernel-pgtable.h | 4 ++-- arch/arm64/kernel/head.S | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm64/include/asm/kernel-pgtable.h +2 -2
@@ -103,8 +103,8 @@/* * Initial memory map attributes. */ -#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) +#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN) +#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PMD_SECT_UXN)#if ARM64_KERNEL_USES_PMD_MAPS #define SWAPPER_MM_MMUFLAGS (PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
arch/arm64/kernel/head.S +1 -1
@@ -285,7 +285,7 @@ SYM_FUNC_START_LOCAL(__create_page_tables) subs x1, x1, #64 b.ne 1b - mov x7, SWAPPER_MM_MMUFLAGS + mov_q x7, SWAPPER_MM_MMUFLAGS /* * Create the identity mapping.
Signature · 1 line
2.37.0.170.g444d1eabd0-goog
Quoted 38 lines · Peter Collingbourne
On a system that implements
FEAT_EPAN, read/write access to the idmap is denied because UXN is not set on the swapper PTEs. As a result,idmap_kpti_install_ng_mappingspanics the kernel when accessing__idmap_kpti_flag. Fix it by setting UXN on these PTEs.Fixes 18107f8a2df6 ("arm64: Support execute-only permissions with Enhanced PAN")Cc <[email protected]> # 5.15Signed-off-by Peter Collingbourne <[email protected]>---
This fix is no longer needed since commitc3cee924bd85("arm64: head:
cover entire kernel image in initial ID map"), which moved__idmap_kpti_flagto .data, but that commit is currently only present in next.arch/arm64/include/asm/kernel-pgtable.h | 4 ++-- arch/arm64/kernel/head.S | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)arch/arm64/include/asm/kernel-pgtable.h +2
-2@@ -103,8 +103,8 @@/* * Initial memory map attributes. */ -#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED) -#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S) +#define SWAPPER_PTE_FLAGS (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN) +#define SWAPPER_PMD_FLAGS (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PMD_SECT_UXN)#if ARM64_KERNEL_USES_PMD_MAPS #define SWAPPER_MM_MMUFLAGS (PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)arch/arm64/kernel/head.S +0
-0
arch/arm64/kernel/head.S SYM_FUNC_START_LOCAL(__create_page_tables) · line 288
Quoted 5 lines
arch/arm64/kernel/head.S +1
-1@@ -285,7 +285,7 @@ SYM_FUNC_START_LOCAL(__create_page_tables) subs x1, x1, #64 b.ne 1b - mov x7, SWAPPER_MM_MMUFLAGS + mov_q x7, SWAPPER_MM_MMUFLAGS
Heh, nice find:
Catalin, I guess this needs to land for 5.19 given that it's no longer relevant after the idmap rework pending for 5.20? If it all explodes in -next, I can merge in for-next/fixes.
Will
Quoted 6 lines · Peter Collingbourne
On a system that implements
FEAT_EPAN, read/write access to the idmap is denied because UXN is not set on the swapper PTEs. As a result,idmap_kpti_install_ng_mappingspanics the kernel when accessing__idmap_kpti_flag. Fix it by setting UXN on these PTEs.
Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64: set UXN on swapper page tables
https://git.kernel.org/arm64/c/f7b4c3b82e7d
Signature · 1 line
Catalin
Catalin Marinas
maintainerQuoted 10 lines · Catalin Marinas
Quoted 4 lines · Peter Collingbourne
On a system that implements
FEAT_EPAN, read/write access to the idmap is denied because UXN is not set on the swapper PTEs. As a result,idmap_kpti_install_ng_mappingspanics the kernel when accessing__idmap_kpti_flag. Fix it by setting UXN on these PTEs.Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64: set UXN on swapper page tables
https://git.kernel.org/arm64/c/f7b4c3b82e7d
I'm dropping this patch from for-next/fixes as it breaks linux-next (interacts badly with stuff already queued). We'll send it to -stable separately as that's no longer needed in mainline after 5.19.
Signature · 1 line
Catalin