Extract DEBUG_WX to shared use.
Subsystems (5)
cover Extract DEBUG_WX to shared use.
Some architectures support DEBUG_WX function, it's verbatim from each others, so extract to mm/Kconfig.debug for shared use.
PPC and ARM ports don't support generic page dumper yet, so we only refine x86 and arm64 port in this patch series.
For RISC-V port, the DEBUG_WX support depends on other patches which be merged already:
- RISC-V page table dumper
- Support strict kernel memory permissions for security
Zong Li (4):
mm: add DEBUG_WX support
riscv: support DEBUG_WX
x86: mm: use ARCH_HAS_DEBUG_WX instead of arch defined
arm64: mm: use ARCH_HAS_DEBUG_WX instead of arch defined
arch/arm64/Kconfig | 1 + arch/arm64/Kconfig.debug | 29 ----------------------------- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/ptdump.h | 6 ++++++ arch/riscv/mm/init.c | 3 +++ arch/x86/Kconfig | 1 + arch/x86/Kconfig.debug | 27 --------------------------- mm/Kconfig.debug | 33 +++++++++++++++++++++++++++++++++ 8 files changed, 45 insertions(+), 56 deletions(-)
Signature · 1 line
2.26.1
PATCH 1/4 mm: add DEBUG_WX support
Some architectures support DEBUG_WX function, it's verbatim from each others. Extract to mm/Kconfig.debug for shared use.
--- mm/Kconfig.debug | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
mm/Kconfig.debug +33 -0
@@ -118,6 +118,39 @@ config DEBUG_RODATA_TEST ---help--- This option enables a testcase for the setting rodata read-only. +config ARCH_HAS_DEBUG_WX + bool + +config DEBUG_WX + bool "Warn on W+X mappings at boot" + depends on ARCH_HAS_DEBUG_WX + select PTDUMP_CORE + help + Generate a warning if any W+X mappings are found at boot. + + This is useful for discovering cases where the kernel is leaving + W+X mappings after applying NX, as such mappings are a security risk. + This check also includes UXN, which should be set on all kernel + mappings. + + Look for a message in dmesg output like this: + + <arch>/mm: Checked W+X mappings: passed, no W+X pages found. + + or like this, if the check failed: + + <arch>/mm: Checked W+X mappings: failed, <N> W+X pages found. + + Note that even if the check fails, your kernel is possibly + still fine, as W+X mappings are not a security hole in + themselves, what they do is that they make the exploitation + of other unfixed kernel bugs easier. + + There is no runtime or memory usage effect of this option + once the kernel has booted up - it's a one time check. + + If in doubt, say "Y". + config GENERIC_PTDUMP bool
Signature · 1 line
2.26.1
PATCH 2/4 riscv: support DEBUG_WX
In reply to Zong LiSupport DEBUG_WX to check whether there are mapping with write and execute permission at the same time.
--- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/ptdump.h | 6 ++++++ arch/riscv/mm/init.c | 3 +++ 3 files changed, 10 insertions(+)
arch/riscv/Kconfig +1 -0
@@ -68,6 +68,7 @@ config RISCV select ARCH_HAS_GCOV_PROFILE_ALL select HAVE_COPY_THREAD_TLS select HAVE_ARCH_KASAN if MMU && 64BIT + select ARCH_HAS_DEBUG_WX config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT
arch/riscv/include/asm/ptdump.h +6 -0
@@ -8,4 +8,10 @@void ptdump_check_wx (void ); +#ifdef CONFIG_DEBUG_WX +#define debug_checkwx () ptdump_check_wx() +#else +#define debug_checkwx () do { } while (0) +#endif +#endif /* _ASM_RISCV_PTDUMP_H */
arch/riscv/mm/init.c +3 -0
@@ -19,6 +19,7 @@#include <asm/sections.h> #include <asm/pgtable.h> #include <asm/io.h> +#include <asm/ptdump.h> #include "../kernel/head.h"
@@ -529,6 +530,8 @@ void mark_rodata_ro(void)set_memory_ro (rodata_start, (data_start - rodata_start) >>PAGE_SHIFT );set_memory_nx (rodata_start, (data_start - rodata_start) >>PAGE_SHIFT );set_memory_nx (data_start, (max_low - data_start) >>PAGE_SHIFT ); + + debug_checkwx(); }#endif
Signature · 1 line
2.26.1
PATCH 3/4 x86: mm: use ARCH_HAS_DEBUG_WX instead of arch defined
In reply to Zong LiExtract DEBUG_WX to mm/Kconfig.debug for shared use. Change to use ARCH_HAS_DEBUG_WX instead of DEBUG_WX defined by arch port.
--- arch/x86/Kconfig | 1 + arch/x86/Kconfig.debug | 27 --------------------------- 2 files changed, 1 insertion(+), 27 deletions(-)
arch/x86/Kconfig +1 -0
@@ -80,6 +80,7 @@ config X86 select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_DEBUG_WX select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI select ARCH_MIGHT_HAVE_PC_PARPORT
arch/x86/Kconfig.debug +0 -27
@@ -72,33 +72,6 @@ config EFI_PGT_DUMP issues with the mapping of the EFI runtime regions into that table. -config DEBUG_WX - bool "Warn on W+X mappings at boot" - select PTDUMP_CORE - ---help--- - Generate a warning if any W+X mappings are found at boot. - - This is useful for discovering cases where the kernel is leaving - W+X mappings after applying NX, as such mappings are a security risk. - - Look for a message in dmesg output like this: - - x86/mm: Checked W+X mappings: passed, no W+X pages found. - - or like this, if the check failed: - - x86/mm: Checked W+X mappings: FAILED, <N> W+X pages found. - - Note that even if the check fails, your kernel is possibly - still fine, as W+X mappings are not a security hole in - themselves, what they do is that they make the exploitation - of other unfixed kernel bugs easier. - - There is no runtime or memory usage effect of this option - once the kernel has booted up - it's a one time check. - - If in doubt, say "Y". - config DOUBLEFAULT default y bool "Enable doublefault exception handler" if EXPERT && X86_32
Signature · 1 line
2.26.1
PATCH 4/4 arm64: mm: use ARCH_HAS_DEBUG_WX instead of arch defined
In reply to Zong LiExtract DEBUG_WX to mm/Kconfig.debug for shared use. Change to use ARCH_HAS_DEBUG_WX instead of DEBUG_WX defined by arch port.
--- arch/arm64/Kconfig | 1 + arch/arm64/Kconfig.debug | 29 ----------------------------- 2 files changed, 1 insertion(+), 29 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -9,6 +9,7 @@ config ARM64 select ACPI_MCFG if (ACPI && PCI) select ACPI_SPCR_TABLE if ACPI select ACPI_PPTT if ACPI + select ARCH_HAS_DEBUG_WX select ARCH_HAS_DEBUG_VIRTUAL select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_HAS_DMA_PREP_COHERENT
arch/arm64/Kconfig.debug +0 -29
@@ -23,35 +23,6 @@ config ARM64_RANDOMIZE_TEXT_OFFSET of TEXT_OFFSET and platforms must not require a specific value. -config DEBUG_WX - bool "Warn on W+X mappings at boot" - select PTDUMP_CORE - ---help--- - Generate a warning if any W+X mappings are found at boot. - - This is useful for discovering cases where the kernel is leaving - W+X mappings after applying NX, as such mappings are a security risk. - This check also includes UXN, which should be set on all kernel - mappings. - - Look for a message in dmesg output like this: - - arm64/mm: Checked W+X mappings: passed, no W+X pages found. - - or like this, if the check failed: - - arm64/mm: Checked W+X mappings: FAILED, <N> W+X pages found. - - Note that even if the check fails, your kernel is possibly - still fine, as W+X mappings are not a security hole in - themselves, what they do is that they make the exploitation - of other unfixed kernel bugs easier. - - There is no runtime or memory usage effect of this option - once the kernel has booted up - it's a one time check. - - If in doubt, say "Y". - config DEBUG_EFI depends on EFI && DEBUG_INFO bool "UEFI debugging"
Signature · 1 line
2.26.1
Andrew Morton
maintainerRe: [PATCH 2/4] riscv: support DEBUG_WX
In reply to Zong LiQuoted 6 lines · On Tue, 21 Apr 2020 16:17:13 +0800 Zong Li <[email protected]> wrote:
Support
DEBUG_WXto check whether there are mapping with write and execute permission at the same time.
arch/riscv/include/asm/ptdump.h line 17
Quoted 10 lines
arch/riscv/include/asm/ptdump.h +6
-0@@ -8,4 +8,10 @@void ptdump_check_wx (void ); +#ifdef CONFIG_DEBUG_WX +#define debug_checkwx () ptdump_check_wx() +#else +#define debug_checkwx () do { } while (0) +#endif +#endif /* _ASM_RISCV_PTDUMP_H */
It's preferred to implement things in regular C, unless they MUST be implemented in the preprocessor. So...
arch/riscv/include/asm/ptdump.h renamed from arch/riscv/include/asm/ptdump.h~riscv-support-debug_wx-fix +7 -2
@@ -9,9 +9,14 @@void ptdump_check_wx (void );#ifdef CONFIG_DEBUG_WX -#define debug_checkwx () ptdump_check_wx() +static inline void debug_checkwx (void ) +{ +ptdump_check_wx (); +}#else -#define debug_checkwx () do { } while (0) +static inline void debug_checkwx (void ) +{ +}#endif #endif /* _ASM_RISCV_PTDUMP_H */
_
Will Deacon
maintainerRe: [PATCH 1/4] mm: add DEBUG_WX support
In reply to Zong LiQuoted 21 lines · Zong Li
Some architectures support
DEBUG_WXfunction, it's verbatim from each others. Extract tomm/Kconfig.debugfor shared use.Signed-off-by Zong Li <[email protected]>Suggested-by Palmer Dabbelt <[email protected]>--- mm/Kconfig.debug | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)mm/Kconfig.debug +4
-0@@ -118,6 +118,39 @@ config DEBUG_RODATA_TEST ---help--- This option enables a testcase for the setting rodata read-only. +config ARCH_HAS_DEBUG_WX + bool + +config DEBUG_WX
mm/Kconfig.debug config DEBUG_RODATA_TEST · line 134
Quoted 10 lines
mm/Kconfig.debug +10
-0+ bool "Warn on W+X mappings at boot" + depends on ARCH_HAS_DEBUG_WX + select PTDUMP_CORE + help + Generate a warning if any W+X mappings are found at boot. + + This is useful for discovering cases where the kernel is leaving + W+X mappings after applying NX, as such mappings are a security risk. + This check also includes UXN, which should be set on all kernel + mappings.
"UXN" is the name of a bit in the arm64 page-table descriptors, so this should be reworded now that it's in generic help text.
Will
Re: [PATCH 4/4] arm64: mm: use ARCH_HAS_DEBUG_WX instead of arch defined
In reply to Zong LiQuoted 8 lines · Zong Li
Extract
DEBUG_WXtomm/Kconfig.debugfor shared use. Change to useARCH_HAS_DEBUG_WXinstead ofDEBUG_WXdefined by arch port.Signed-off-by Zong Li <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/Kconfig.debug | 29 ----------------------------- 2 files changed, 1 insertion(+), 29 deletions(-)
Will
Re: [PATCH 1/4] mm: add DEBUG_WX support
In reply to Will DeaconQuoted 28 lines · Will Deacon
Quoted 26 lines · Zong Li
Some architectures support
DEBUG_WXfunction, it's verbatim from each others. Extract tomm/Kconfig.debugfor shared use.Signed-off-by Zong Li <[email protected]>Suggested-by Palmer Dabbelt <[email protected]>--- mm/Kconfig.debug | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)mm/Kconfig.debug +9
-0@@ -118,6 +118,39 @@ config DEBUG_RODATA_TEST ---help--- This option enables a testcase for the setting rodata read-only. +config ARCH_HAS_DEBUG_WX + bool + +config DEBUG_WX + bool "Warn on W+X mappings at boot" + depends on ARCH_HAS_DEBUG_WX + select PTDUMP_CORE + help + Generate a warning if any W+X mappings are found at boot.
Quoted 9 lines
mm/Kconfig.debug config DEBUG_RODATA_TEST · line 134
Quoted 5 lines
mm/Kconfig.debug +5
-0+ + This is useful for discovering cases where the kernel is leaving + W+X mappings after applying NX, as such mappings are a security risk. + This check also includes UXN, which should be set on all kernel + mappings."UXN" is the name of a bit in the arm64 page-table descriptors, so this should be reworded now that it's in generic help text.
It's exactly. Sorry for missing the statement.
Hi Andrew,
Shall I send a next version patch to fix it? It should be "This is useful for discovering cases where the kernel is leaving W+X mappings after applying NX, as such mappings are a security risk." here.
Quoted 1 line
Will
Andrew Morton
maintainerRe: [PATCH 1/4] mm: add DEBUG_WX support
Quoted 9 lines · On Mon, 27 Apr 2020 16:47:47 +0800 Zong Li <[email protected]> wrote:
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ This is useful for discovering cases where the kernel is leaving + W+X mappings after applying NX, as such mappings are a security risk. + This check also includes UXN, which should be set on all kernel + mappings."UXN" is the name of a bit in the arm64 page-table descriptors, so this should be reworded now that it's in generic help text.
Quoted 6 lines
It's exactly. Sorry for missing the statement.
Hi Andrew,
Shall I send a next version patch to fix it? It should be "This is useful for discovering cases where the kernel is leaving W+X mappings after applying NX, as such mappings are a security risk." here.
I'll add this:
mm/Kconfig.debug renamed from mm/Kconfig.debug~mm-add-debug_wx-support-fix +2 -2
@@ -128,8 +128,8 @@ config DEBUG_WX help Generate a warning if any W+X mappings are found at boot. - This is useful for discovering cases where the kernel is leaving - W+X mappings after applying NX, as such mappings are a security risk. + This is useful for discovering cases where the kernel is leaving W+X + mappings after applying NX, as such mappings are a security risk. This check also includes UXN, which should be set on all kernel mappings.
_