]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
arch: Move CONFIG_DEBUG_RODATA and CONFIG_SET_MODULE_RONX to be common
authorLaura Abbott <labbott@redhat.com>
Tue, 7 Feb 2017 00:31:57 +0000 (16:31 -0800)
committerKees Cook <keescook@chromium.org>
Tue, 7 Feb 2017 20:32:52 +0000 (12:32 -0800)
There are multiple architectures that support CONFIG_DEBUG_RODATA and
CONFIG_SET_MODULE_RONX. These options also now have the ability to be
turned off at runtime. Move these to an architecture independent
location and make these options def_bool y for almost all of those
arches.

Signed-off-by: Laura Abbott <labbott@redhat.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
13 files changed:
Documentation/security/self-protection.txt
arch/Kconfig
arch/arm/Kconfig
arch/arm/Kconfig.debug
arch/arm/mm/Kconfig
arch/arm64/Kconfig
arch/arm64/Kconfig.debug
arch/parisc/Kconfig
arch/parisc/Kconfig.debug
arch/s390/Kconfig
arch/s390/Kconfig.debug
arch/x86/Kconfig
arch/x86/Kconfig.debug

index 3010576c9fca047af63b668a926e6bd9f923563d..f41dd00e8b98abb3db3e3f143f51c4f7730b8cd7 100644 (file)
@@ -56,6 +56,12 @@ CONFIG_DEBUG_SET_MODULE_RONX, which seek to make sure that code is not
 writable, data is not executable, and read-only data is neither writable
 nor executable.
 
+Most architectures have these options on by default and not user selectable.
+For some architectures like arm that wish to have these be selectable,
+the architecture Kconfig can select ARCH_OPTIONAL_KERNEL_RWX to enable
+a Kconfig prompt. CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT determines
+the default setting when ARCH_OPTIONAL_KERNEL_RWX is enabled.
+
 #### Function pointers and sensitive variables must not be writable
 
 Vast areas of kernel memory contain function pointers that are looked
index 99839c23d453fa8ded2061968aead8a6ee4b2317..3f8b8be3036ffd59c963c4598b1b197b1eb9c6fd 100644 (file)
@@ -781,4 +781,38 @@ config VMAP_STACK
          the stack to map directly to the KASAN shadow map using a formula
          that is incorrect if the stack is in vmalloc space.
 
+config ARCH_OPTIONAL_KERNEL_RWX
+       def_bool n
+
+config ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
+       def_bool n
+
+config ARCH_HAS_STRICT_KERNEL_RWX
+       def_bool n
+
+config DEBUG_RODATA
+       bool "Make kernel text and rodata read-only" if ARCH_OPTIONAL_KERNEL_RWX
+       depends on ARCH_HAS_STRICT_KERNEL_RWX
+       default !ARCH_OPTIONAL_KERNEL_RWX || ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
+       help
+         If this is set, kernel text and rodata memory will be made read-only,
+         and non-text memory will be made non-executable. This provides
+         protection against certain security exploits (e.g. executing the heap
+         or modifying text)
+
+         These features are considered standard security practice these days.
+         You should say Y here in almost all cases.
+
+config ARCH_HAS_STRICT_MODULE_RWX
+       def_bool n
+
+config DEBUG_SET_MODULE_RONX
+       bool "Set loadable kernel module data as NX and text as RO" if ARCH_OPTIONAL_KERNEL_RWX
+       depends on ARCH_HAS_STRICT_MODULE_RWX && MODULES
+       default !ARCH_OPTIONAL_KERNEL_RWX || ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
+       help
+         If this is set, module text and rodata memory will be made read-only,
+         and non-text memory will be made non-executable. This provides
+         protection against certain security exploits (e.g. writing to text)
+
 source "kernel/gcov/Kconfig"
index 5fab553fd03ade24fdc1a69a83e5092b791b8a01..8c88c8ad064bdc0ea43582d078c3742a6db7bb1d 100644 (file)
@@ -4,10 +4,14 @@ config ARM
        select ARCH_CLOCKSOURCE_DATA
        select ARCH_HAS_DEVMEM_IS_ALLOWED
        select ARCH_HAS_ELF_RANDOMIZE
+       select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
+       select ARCH_HAS_STRICT_MODULE_RWX if MMU
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_HAVE_CUSTOM_GPIO_H
        select ARCH_HAS_GCOV_PROFILE_ALL
        select ARCH_MIGHT_HAVE_PC_PARPORT
+       select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
+       select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7
        select ARCH_SUPPORTS_ATOMIC_RMW
        select ARCH_USE_BUILTIN_BSWAP
        select ARCH_USE_CMPXCHG_LOCKREF
index d83f7c369e514de41cfa0d56fc7c64b0e7bad256..426d2716f55d37603de6b2eab2114a19af625418 100644 (file)
@@ -1738,17 +1738,6 @@ config PID_IN_CONTEXTIDR
          additional instructions during context switch. Say Y here only if you
          are planning to use hardware trace tools with this kernel.
 
-config DEBUG_SET_MODULE_RONX
-       bool "Set loadable kernel module data as NX and text as RO"
-       depends on MODULES && MMU
-       ---help---
-         This option helps catch unintended modifications to loadable
-         kernel module's text and read-only data. It also prevents execution
-         of module data. Such protection may interfere with run-time code
-         patching and dynamic kernel tracing - and they might also protect
-         against certain classes of kernel exploits.
-         If in doubt, say "N".
-
 source "drivers/hwtracing/coresight/Kconfig"
 
 endmenu
index f68e8ec294473d9b44991610a8dbcba7d12b9c76..419a0355d4e4d48f2cbc9ab0fde1344be7c70b64 100644 (file)
@@ -1051,18 +1051,6 @@ config ARCH_SUPPORTS_BIG_ENDIAN
          This option specifies the architecture can support big endian
          operation.
 
-config DEBUG_RODATA
-       bool "Make kernel text and rodata read-only"
-       depends on MMU && !XIP_KERNEL
-       default y if CPU_V7
-       help
-         If this is set, kernel text and rodata memory will be made
-         read-only, and non-text kernel memory will be made non-executable.
-         The tradeoff is that each region is padded to section-size (1MiB)
-         boundaries (because their permissions are different and splitting
-         the 1M pages into 4K ones causes TLB performance problems), which
-         can waste memory.
-
 config DEBUG_ALIGN_RODATA
        bool "Make rodata strictly non-executable"
        depends on DEBUG_RODATA
index 1117421268976b62dd4e77cd3a523c10070f3ace..e1efbcc9de32a779a637dee044a76244b4d38b30 100644 (file)
@@ -13,6 +13,8 @@ config ARM64
        select ARCH_HAS_GIGANTIC_PAGE
        select ARCH_HAS_KCOV
        select ARCH_HAS_SG_CHAIN
+       select ARCH_HAS_STRICT_KERNEL_RWX
+       select ARCH_HAS_STRICT_MODULE_RWX
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_USE_CMPXCHG_LOCKREF
        select ARCH_SUPPORTS_ATOMIC_RMW
@@ -123,9 +125,6 @@ config ARCH_PHYS_ADDR_T_64BIT
 config MMU
        def_bool y
 
-config DEBUG_RODATA
-       def_bool y
-
 config ARM64_PAGE_SHIFT
        int
        default 16 if ARM64_64K_PAGES
index d1ebd46872fdf746b1f2c84e0af3959522051009..939815e8d695444d24ddcd13c1d9c5d5fc204c08 100644 (file)
@@ -71,17 +71,6 @@ config DEBUG_WX
 
          If in doubt, say "Y".
 
-config DEBUG_SET_MODULE_RONX
-       bool "Set loadable kernel module data as NX and text as RO"
-       depends on MODULES
-       default y
-       help
-         Is this is set, kernel module text and rodata will be made read-only.
-         This is to help catch accidental or malicious attempts to change the
-         kernel's executable code.
-
-         If in doubt, say Y.
-
 config DEBUG_ALIGN_RODATA
        depends on DEBUG_RODATA
        bool "Align linker sections up to SECTION_SIZE"
index 3a71f38cdc0553eeb8c026b2b12d3b412e2f2657..ad294b3fb90be4bb4e4a800fdd50354e7a5e970c 100644 (file)
@@ -8,6 +8,7 @@ config PARISC
        select HAVE_SYSCALL_TRACEPOINTS
        select ARCH_WANT_FRAME_POINTERS
        select ARCH_HAS_ELF_RANDOMIZE
+       select ARCH_HAS_STRICT_KERNEL_RWX
        select RTC_CLASS
        select RTC_DRV_GENERIC
        select INIT_ALL_POSSIBLE
index 68b7cbd0810a77bf321f524b9c8809b508f864d6..0d856b94c9b1126c7e21c1bdb97cc8087dbbfb71 100644 (file)
@@ -5,15 +5,4 @@ source "lib/Kconfig.debug"
 config TRACE_IRQFLAGS_SUPPORT
        def_bool y
 
-config DEBUG_RODATA
-       bool "Write protect kernel read-only data structures"
-       depends on DEBUG_KERNEL
-       default y
-       help
-         Mark the kernel read-only data as write-protected in the pagetables,
-         in order to catch accidental (and incorrect) writes to such const
-         data. This option may have a slight performance impact because a
-         portion of the kernel code won't be covered by a TLB anymore.
-         If in doubt, say "N".
-
 endmenu
index c6722112527d6ed5937bd98870dbb8fb843b3dd1..53bb0e3e0db3cc2eb4112143a174237cda85a392 100644 (file)
@@ -62,9 +62,6 @@ config PCI_QUIRKS
 config ARCH_SUPPORTS_UPROBES
        def_bool y
 
-config DEBUG_RODATA
-       def_bool y
-
 config S390
        def_bool y
        select ARCH_HAS_DEVMEM_IS_ALLOWED
@@ -73,6 +70,8 @@ config S390
        select ARCH_HAS_GIGANTIC_PAGE
        select ARCH_HAS_KCOV
        select ARCH_HAS_SG_CHAIN
+       select ARCH_HAS_STRICT_KERNEL_RWX
+       select ARCH_HAS_STRICT_MODULE_RWX
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARCH_HAVE_NMI_SAFE_CMPXCHG
        select ARCH_INLINE_READ_LOCK
index 26c5d5beb4bebd2e060654d2d9d6e480f7f5da34..57f8ea9c49e32714bced886a1348a5e38728a77d 100644 (file)
@@ -17,7 +17,4 @@ config S390_PTDUMP
          kernel.
          If in doubt, say "N"
 
-config DEBUG_SET_MODULE_RONX
-       def_bool y
-       depends on MODULES
 endmenu
index e487493bbd47f0f84caed99f6c952bf6b3062413..13e1bf4b0fe5cd4dbb6e2da93b9034b628399994 100644 (file)
@@ -54,6 +54,8 @@ config X86
        select ARCH_HAS_MMIO_FLUSH
        select ARCH_HAS_PMEM_API                if X86_64
        select ARCH_HAS_SG_CHAIN
+       select ARCH_HAS_STRICT_KERNEL_RWX
+       select ARCH_HAS_STRICT_MODULE_RWX
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARCH_HAVE_NMI_SAFE_CMPXCHG
        select ARCH_MIGHT_HAVE_ACPI_PDC         if ACPI
@@ -309,9 +311,6 @@ config ARCH_SUPPORTS_UPROBES
 config FIX_EARLYCON_MEM
        def_bool y
 
-config DEBUG_RODATA
-       def_bool y
-
 config PGTABLE_LEVELS
        int
        default 4 if X86_64
index 67eec55093a5dc97634aea899c4be86ff9f18f00..69cdd0b2176b54b1e1f5a7c03efa4e9f028b7b5a 100644 (file)
@@ -109,17 +109,6 @@ config DEBUG_WX
 
          If in doubt, say "Y".
 
-config DEBUG_SET_MODULE_RONX
-       bool "Set loadable kernel module data as NX and text as RO"
-       depends on MODULES
-       ---help---
-         This option helps catch unintended modifications to loadable
-         kernel module's text and read-only data. It also prevents execution
-         of module data. Such protection may interfere with run-time code
-         patching and dynamic kernel tracing - and they might also protect
-         against certain classes of kernel exploits.
-         If in doubt, say "N".
-
 config DEBUG_NX_TEST
        tristate "Testcase for the NX non-executable stack feature"
        depends on DEBUG_KERNEL && m