Better hardening names
Subsystems (13)
cover Better hardening names
Hi,
It's come up previously that CONFIG_DEBUG_SET_MODULE_RONX and CONFIG_DEBUG_RODATA are not accurate names, mostly they should not have the word 'debug' in them. This series attempts to change the names to something a bit more descriptive and indicative of what they are actually used for these days.
I marked this RFC for
- Bike shedding purposes.
- A discussion of what defaults should be. The way I did the refactoring, both options are default y. I'd appreciate comments if there is a better approach.
- Approach to split this up into more sub patches to make review/merging easier? Or maybe it's fine.
Quickly tested on arm/arm64/x86.
Thanks,
Laura
Laura Abbott (2):
security: Change name of CONFIG_DEBUG_RODATA
security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
Documentation/DocBook/kgdb.tmpl | 8 ++++---- Documentation/security/self-protection.txt | 4 ++-- arch/arm/Kconfig | 2 ++ arch/arm/Kconfig.debug | 11 ---------- arch/arm/configs/aspeed_g4_defconfig | 4 ++-- arch/arm/configs/aspeed_g5_defconfig | 4 ++-- arch/arm/include/asm/cacheflush.h | 2 +- arch/arm/kernel/patch.c | 4 ++-- arch/arm/kernel/vmlinux.lds.S | 8 ++++---- arch/arm/mm/Kconfig | 14 +------------ arch/arm/mm/init.c | 4 ++-- arch/arm64/Kconfig | 5 ++--- arch/arm64/Kconfig.debug | 13 +----------- arch/arm64/kernel/insn.c | 2 +- arch/parisc/Kconfig | 1 + arch/parisc/Kconfig.debug | 11 ---------- arch/parisc/configs/712_defconfig | 2 +- arch/parisc/configs/c3000_defconfig | 2 +- arch/parisc/mm/init.c | 2 +- arch/s390/Kconfig | 5 ++--- arch/s390/Kconfig.debug | 3 --- arch/x86/Kconfig | 5 ++--- arch/x86/Kconfig.debug | 11 ---------- include/linux/filter.h | 4 ++-- include/linux/init.h | 4 ++-- include/linux/module.h | 2 +- init/main.c | 4 ++-- kernel/configs/android-recommended.config | 2 +- kernel/module.c | 6 +++--- kernel/power/hibernate.c | 2 +- kernel/power/power.h | 4 ++-- kernel/power/snapshot.c | 4 ++-- security/Kconfig | 32 ++++++++++++++++++++++++++++++ 33 files changed, 82 insertions(+), 109 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 security: Change name of CONFIG_DEBUG_RODATA
Despite the word 'debug' in CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name to CONFIG_HARDENED_PAGE_MAPPINGS which more accurately describes what this option is intended to do.
--- Documentation/DocBook/kgdb.tmpl | 8 ++++---- Documentation/security/self-protection.txt | 2 +- arch/arm/Kconfig | 1 + arch/arm/configs/aspeed_g4_defconfig | 2 +- arch/arm/configs/aspeed_g5_defconfig | 2 +- arch/arm/include/asm/cacheflush.h | 2 +- arch/arm/kernel/patch.c | 2 +- arch/arm/kernel/vmlinux.lds.S | 8 ++++---- arch/arm/mm/Kconfig | 14 +------------- arch/arm/mm/init.c | 4 ++-- arch/arm64/Kconfig | 4 +--- arch/arm64/Kconfig.debug | 2 +- arch/parisc/Kconfig | 1 + arch/parisc/Kconfig.debug | 11 ----------- arch/parisc/configs/712_defconfig | 2 +- arch/parisc/configs/c3000_defconfig | 2 +- arch/parisc/mm/init.c | 2 +- arch/s390/Kconfig | 4 +--- arch/x86/Kconfig | 4 +--- include/linux/init.h | 4 ++-- init/main.c | 4 ++-- kernel/configs/android-recommended.config | 2 +- kernel/power/hibernate.c | 2 +- kernel/power/power.h | 4 ++-- kernel/power/snapshot.c | 4 ++-- security/Kconfig | 16 ++++++++++++++++ 26 files changed, 51 insertions(+), 62 deletions(-)
Documentation/DocBook/kgdb.tmpl +4 -4
@@ -115,12 +115,12 @@ </para> <para> If the architecture that you are using supports the kernel option - CONFIG_DEBUG_RODATA, you should consider turning it off. This + CONFIG_HARDENED_PAGE_MAPPINGS, you should consider turning it off. This option will prevent the use of software breakpoints because it marks certain regions of the kernel's memory space as read-only. If kgdb supports it for the architecture you are using, you can use hardware breakpoints if you desire to run with the - CONFIG_DEBUG_RODATA option turned on, else you need to turn off + CONFIG_HARDENED_PAGE_MAPPINGS option turned on, else you need to turn off this option. </para> <para>
@@ -135,7 +135,7 @@ <para>Here is an example set of .config symbols to enable or disable for kgdb: <itemizedlist> - <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para># CONFIG_HARDENED_PAGE_MAPPINGS is not set</para></listitem> <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> <listitem><para>CONFIG_KGDB=y</para></listitem> <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem>
@@ -166,7 +166,7 @@ </para> <para>Here is an example set of .config symbols to enable/disable kdb: <itemizedlist> - <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para># CONFIG_HARDENED_PAGE_MAPPINGS is not set</para></listitem> <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> <listitem><para>CONFIG_KGDB=y</para></listitem> <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem>
Documentation/security/self-protection.txt +1 -1
@@ -51,7 +51,7 @@ kernel, they are implemented in a way where the memory is temporarily made writable during the update, and then returned to the original permissions.) -In support of this are (the poorly named) CONFIG_DEBUG_RODATA and +In support of this are CONFIG_HARDENED_PAGE_MAPPINGS and 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.
arch/arm/Kconfig +1 -0
@@ -7,6 +7,7 @@ config ARM select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_HARDENED_MAPPINGS if MMU && !XIP_KERNEL select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAP
arch/arm/configs/aspeed_g4_defconfig +1 -1
@@ -25,7 +25,7 @@ CONFIG_MODULE_UNLOAD=y # CONFIG_ARCH_MULTI_V7 is not set CONFIG_ARCH_ASPEED=y CONFIG_MACH_ASPEED_G4=y -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_AEABI=y CONFIG_UACCESS_WITH_MEMCPY=y CONFIG_SECCOMP=y
arch/arm/configs/aspeed_g5_defconfig +1 -1
@@ -26,7 +26,7 @@ CONFIG_ARCH_MULTI_V6=y # CONFIG_ARCH_MULTI_V7 is not set CONFIG_ARCH_ASPEED=y CONFIG_MACH_ASPEED_G5=y -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_AEABI=y CONFIG_UACCESS_WITH_MEMCPY=y CONFIG_SECCOMP=y
arch/arm/include/asm/cacheflush.h +1 -1
@@ -490,7 +490,7 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; }#endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS void set_kernel_text_rw (void );void set_kernel_text_ro (void );#else
arch/arm/kernel/patch.c +1 -1
@@ -26,7 +26,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)if (module &&IS_ENABLED (CONFIG_DEBUG_SET_MODULE_RONX )) page =vmalloc_to_page (addr); -else if (!module &&IS_ENABLED (CONFIG_DEBUG_RODATA )) +else if (!module &&IS_ENABLED (CONFIG_HARDENED_PAGE_MAPPINGS )) page =virt_to_page (addr);else return addr;
arch/arm/kernel/vmlinux.lds.S +4 -4
@@ -97,7 +97,7 @@ SECTIONS HEAD_TEXT } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS . = ALIGN(1<<SECTION_SHIFT); #endif
@@ -158,7 +158,7 @@ SECTIONS NOTES -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS . = ALIGN(1<<SECTION_SHIFT); #else . = ALIGN(PAGE_SIZE);
@@ -230,7 +230,7 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) #endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS . = ALIGN(1<<SECTION_SHIFT); #else . = ALIGN(THREAD_SIZE);
@@ -325,7 +325,7 @@ SECTIONS STABS_DEBUG } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS /* * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will * be the first section-aligned location after __start_rodata. Otherwise,
arch/arm/mm/Kconfig +1 -13
@@ -1051,21 +1051,9 @@ 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 + depends on HARDENED_PAGE_MAPPINGS default y help If this is set, rodata will be made explicitly non-executable. This
arch/arm/mm/init.c +2 -2
@@ -572,7 +572,7 @@ void __init mem_init(void) } } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS struct section_perm { const char *name; unsigned long start;
@@ -741,7 +741,7 @@ void set_kernel_text_ro(void)#else static inline void fix_kernmem_perms (void ) { } -#endif /* CONFIG_DEBUG_RODATA */ +#endif /* CONFIG_HARDENED_PAGE_MAPPINGS */ void free_tcmmem (void ) {
arch/arm64/Kconfig +1 -3
@@ -11,6 +11,7 @@ config ARM64 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
@@ -123,9 +124,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
arch/arm64/Kconfig.debug +1 -1
@@ -83,7 +83,7 @@ config DEBUG_SET_MODULE_RONX If in doubt, say Y. config DEBUG_ALIGN_RODATA - depends on DEBUG_RODATA + depends on ARCH_HAS_HARDENED_MAPPINGS bool "Align linker sections up to SECTION_SIZE" help If this option is enabled, sections that may potentially be marked as
arch/parisc/Kconfig +1 -0
@@ -8,6 +8,7 @@ config PARISC select HAVE_SYSCALL_TRACEPOINTS select ARCH_WANT_FRAME_POINTERS select ARCH_HAS_ELF_RANDOMIZE + select ARCH_HAS_HARDENED_MAPPINGS select RTC_CLASS select RTC_DRV_GENERIC select INIT_ALL_POSSIBLE
arch/parisc/Kconfig.debug +0 -11
@@ -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
arch/parisc/configs/712_defconfig +1 -1
@@ -182,7 +182,7 @@ CONFIG_DEBUG_FS=y CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_MUTEXES=y # CONFIG_RCU_CPU_STALL_DETECTOR is not set -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_CRYPTO_NULL=m CONFIG_CRYPTO_TEST=m CONFIG_CRYPTO_HMAC=y
arch/parisc/configs/c3000_defconfig +1 -1
@@ -166,7 +166,7 @@ CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_MUTEXES=y # CONFIG_DEBUG_BUGVERBOSE is not set # CONFIG_RCU_CPU_STALL_DETECTOR is not set -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_CRYPTO_NULL=m CONFIG_CRYPTO_TEST=m CONFIG_CRYPTO_MD5=m
arch/parisc/mm/init.c +1 -1
@@ -545,7 +545,7 @@ void free_initmem(void) } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS void mark_rodata_ro (void ) {/* rodata memory was already mapped with KERNEL_RO access rights by
arch/s390/Kconfig +1 -3
@@ -62,15 +62,13 @@ 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 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_UBSAN_SANITIZE_ALL
arch/x86/Kconfig +1 -3
@@ -50,6 +50,7 @@ config X86 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV if X86_64 select ARCH_HAS_MMIO_FLUSH select ARCH_HAS_PMEM_API if X86_64
@@ -309,9 +310,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
include/linux/init.h +2 -2
@@ -126,10 +126,10 @@ void prepare_namespace(void);void __init load_default_modules (void );int __init init_rootfs (void ); -#if defined(CONFIG_DEBUG_RODATA ) || defined(CONFIG_DEBUG_SET_MODULE_RONX ) +#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_DEBUG_SET_MODULE_RONX )extern bool rodata_enabled;#endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS void mark_rodata_ro (void );#endif
init/main.c +2 -2
@@ -925,7 +925,7 @@ static int try_to_run_init_process(const char *init_filename) static noinline void __init kernel_init_freeable(void); -#if defined(CONFIG_DEBUG_RODATA ) || defined(CONFIG_DEBUG_SET_MODULE_RONX ) +#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_DEBUG_SET_MODULE_RONX )bool rodata_enabled__ro_after_init = true;static int __init set_debug_rodata (char *str) {
@@ -934,7 +934,7 @@ static int __init set_debug_rodata(char *str)__setup ("rodata=" , set_debug_rodata);#endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS static void mark_readonly (void ) {if (rodata_enabled)
kernel/configs/android-recommended.config +1 -1
@@ -11,7 +11,7 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=8192 CONFIG_COMPACTION=y -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_DM_CRYPT=y CONFIG_DM_UEVENT=y CONFIG_DM_VERITY=y
kernel/power/hibernate.c +1 -1
@@ -1156,7 +1156,7 @@ static int __init hibernate_setup(char *str) }else if (!strncmp (str,"no" ,2 )) { noresume =1 ; nohibernate =1 ; - }else if (IS_ENABLED (CONFIG_DEBUG_RODATA ) + }else if (IS_ENABLED (CONFIG_HARDENED_PAGE_MAPPINGS ) && !strncmp (str,"protect_image" ,13 )) {enable_restore_image_protection (); }
kernel/power/power.h +2 -2
@@ -61,12 +61,12 @@ extern int hibernation_snapshot(int platform_mode);extern int hibernation_restore (int platform_mode);extern int hibernation_platform_enter (void ); -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS /* kernel/power/snapshot.c */ extern void enable_restore_image_protection (void );#else static inline void enable_restore_image_protection (void ) {} -#endif /* CONFIG_DEBUG_RODATA */ +#endif /* CONFIG_HARDENED_PAGE_MAPPINGS */ #else /* !CONFIG_HIBERNATION */
kernel/power/snapshot.c +2 -2
@@ -38,7 +38,7 @@#include "power.h" -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS static bool hibernate_restore_protection;static bool hibernate_restore_protection_active;
@@ -73,7 +73,7 @@ static inline void hibernate_restore_protection_begin(void) {}static inline void hibernate_restore_protection_end (void ) {}static inline void hibernate_restore_protect_page (void *page_address) {}static inline void hibernate_restore_unprotect_page (void *page_address) {} -#endif /* CONFIG_DEBUG_RODATA */ +#endif /* CONFIG_HARDENED_PAGE_MAPPINGS */ static int swsusp_page_is_free (struct page *);static void swsusp_set_page_forbidden (struct page *);
security/Kconfig +16 -0
@@ -158,6 +158,22 @@ config HARDENED_USERCOPY_PAGESPAN been removed. This config is intended to be used only while trying to find such users. +config ARCH_HAS_HARDENED_MAPPINGS + def_bool n + +config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. + source security/selinux/Kconfig source security/smack/Kconfig source security/tomoyo/Kconfig
Signature · 1 line
2.7.4
PATCH 2/2 security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
In reply to Laura AbbottDespite the word 'debug' in CONFIG_DEBUG_SET_MODULE_RONX, this kernel option provides key security features that are to be expected on a modern system. Change the name to CONFIG_HARDENED_MODULE_MAPPINGS which more accurately describes what this option is intended to do.
--- Documentation/security/self-protection.txt | 2 +- arch/arm/Kconfig | 1 + arch/arm/Kconfig.debug | 11 ----------- arch/arm/configs/aspeed_g4_defconfig | 2 +- arch/arm/configs/aspeed_g5_defconfig | 2 +- arch/arm/kernel/patch.c | 2 +- arch/arm64/Kconfig | 1 + arch/arm64/Kconfig.debug | 11 ----------- arch/arm64/kernel/insn.c | 2 +- arch/s390/Kconfig | 1 + arch/s390/Kconfig.debug | 3 --- arch/x86/Kconfig | 1 + arch/x86/Kconfig.debug | 11 ----------- include/linux/filter.h | 4 ++-- include/linux/init.h | 2 +- include/linux/module.h | 2 +- init/main.c | 2 +- kernel/module.c | 6 +++--- security/Kconfig | 16 ++++++++++++++++ 19 files changed, 33 insertions(+), 49 deletions(-)
Documentation/security/self-protection.txt +1 -1
@@ -52,7 +52,7 @@ made writable during the update, and then returned to the original permissions.) In support of this are CONFIG_HARDENED_PAGE_MAPPINGS and -CONFIG_DEBUG_SET_MODULE_RONX, which seek to make sure that code is not +CONFIG_HARDENED_MODULE_MAPPINGS, which seek to make sure that code is not writable, data is not executable, and read-only data is neither writable nor executable.
arch/arm/Kconfig +1 -0
@@ -8,6 +8,7 @@ config ARM select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HARDENED_MAPPINGS if MMU && !XIP_KERNEL + select ARCH_HAS_HARDENED_MODULE_MAPPINGS if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAP
arch/arm/Kconfig.debug +0 -11
@@ -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
arch/arm/configs/aspeed_g4_defconfig +1 -1
@@ -79,7 +79,7 @@ CONFIG_DEBUG_LL_UART_8250=y CONFIG_DEBUG_UART_PHYS=0x1e784000 CONFIG_DEBUG_UART_VIRT=0xe8784000 CONFIG_EARLY_PRINTK=y -CONFIG_DEBUG_SET_MODULE_RONX=y +CONFIG_HARDENED_MODULE_MAPPINGS=y # CONFIG_XZ_DEC_X86 is not set # CONFIG_XZ_DEC_POWERPC is not set # CONFIG_XZ_DEC_IA64 is not set
arch/arm/configs/aspeed_g5_defconfig +1 -1
@@ -81,7 +81,7 @@ CONFIG_DEBUG_LL_UART_8250=y CONFIG_DEBUG_UART_PHYS=0x1e784000 CONFIG_DEBUG_UART_VIRT=0xe8784000 CONFIG_EARLY_PRINTK=y -CONFIG_DEBUG_SET_MODULE_RONX=y +CONFIG_HARDENED_MODULE_MAPPINGS=y # CONFIG_XZ_DEC_X86 is not set # CONFIG_XZ_DEC_POWERPC is not set # CONFIG_XZ_DEC_IA64 is not set
arch/arm/kernel/patch.c +1 -1
@@ -24,7 +24,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)bool module = !core_kernel_text (uintaddr);struct page *page; -if (module &&IS_ENABLED (CONFIG_DEBUG_SET_MODULE_RONX )) +if (module &&IS_ENABLED (CONFIG_HARDENED_MODULE_MAPPINGS )) page =vmalloc_to_page (addr);else if (!module &&IS_ENABLED (CONFIG_HARDENED_PAGE_MAPPINGS )) page =virt_to_page (addr);
arch/arm64/Kconfig +1 -0
@@ -12,6 +12,7 @@ config ARM64 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
arch/arm64/Kconfig.debug +0 -11
@@ -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 ARCH_HAS_HARDENED_MAPPINGS bool "Align linker sections up to SECTION_SIZE"
arch/arm64/kernel/insn.c +1 -1
@@ -93,7 +93,7 @@ static void __kprobes *patch_map(void *addr, int fixmap)bool module = !core_kernel_text (uintaddr);struct page *page; -if (module &&IS_ENABLED (CONFIG_DEBUG_SET_MODULE_RONX )) +if (module &&IS_ENABLED (CONFIG_HARDENED_MODULE_MAPPINGS )) page =vmalloc_to_page (addr);else if (!module) page =pfn_to_page (PHYS_PFN (__pa (addr)));
arch/s390/Kconfig +1 -0
@@ -69,6 +69,7 @@ config S390 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_UBSAN_SANITIZE_ALL
arch/s390/Kconfig.debug +0 -3
@@ -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
arch/x86/Kconfig +1 -0
@@ -51,6 +51,7 @@ config X86 select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV if X86_64 select ARCH_HAS_MMIO_FLUSH select ARCH_HAS_PMEM_API if X86_64
arch/x86/Kconfig.debug +0 -11
@@ -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
include/linux/filter.h +2 -2
@@ -545,7 +545,7 @@ static inline bool bpf_prog_was_classic(const struct bpf_prog *prog)#define bpf_classic_proglen (fprog) (fprog->len * sizeof(fprog->filter[0])) -#ifdef CONFIG_DEBUG_SET_MODULE_RONX +#ifdef CONFIG_HARDENED_MODULE_MAPPINGS static inline void bpf_prog_lock_ro (struct bpf_prog *fp) {set_memory_ro ((unsigned long )fp, fp->pages);
@@ -563,7 +563,7 @@ static inline void bpf_prog_lock_ro(struct bpf_prog *fp)static inline void bpf_prog_unlock_ro (struct bpf_prog *fp) { } -#endif /* CONFIG_DEBUG_SET_MODULE_RONX */ +#endif /* CONFIG_HARDENED_MODULE_MAPPINGS */ int sk_filter_trim_cap (struct sock *sk,struct sk_buff *skb,unsigned int cap);static inline int sk_filter (struct sock *sk,struct sk_buff *skb)
include/linux/init.h +1 -1
@@ -126,7 +126,7 @@ void prepare_namespace(void);void __init load_default_modules (void );int __init init_rootfs (void ); -#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_DEBUG_SET_MODULE_RONX ) +#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_HARDENED_MODULE_MAPPINGS )extern bool rodata_enabled;#endif #ifdef CONFIG_HARDENED_PAGE_MAPPINGS
include/linux/module.h +1 -1
@@ -764,7 +764,7 @@ extern int module_sysfs_initialized;#define __MODULE_STRING (x) __stringify(x) -#ifdef CONFIG_DEBUG_SET_MODULE_RONX +#ifdef CONFIG_HARDENED_MODULE_MAPPINGS extern void set_all_modules_text_rw (void );extern void set_all_modules_text_ro (void );extern void module_enable_ro (const struct module *mod,bool after_init);
init/main.c +1 -1
@@ -925,7 +925,7 @@ static int try_to_run_init_process(const char *init_filename) static noinline void __init kernel_init_freeable(void); -#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_DEBUG_SET_MODULE_RONX ) +#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_HARDENED_MODULE_MAPPINGS )bool rodata_enabled__ro_after_init = true;static int __init set_debug_rodata (char *str) {
kernel/module.c +3 -3
@@ -74,9 +74,9 @@/* * Modules' sections will be aligned on page boundaries * to ensure complete separation of code and data, but -* only when CONFIG_DEBUG_SET_MODULE_RONX=y +* only when CONFIG_HARDENED_MODULE_MAPPINGS=y */ -#ifdef CONFIG_DEBUG_SET_MODULE_RONX +#ifdef CONFIG_HARDENED_MODULE_MAPPINGS # define debug_align (X ) ALIGN(X, PAGE_SIZE)#else # define debug_align (X ) (X)
@@ -1847,7 +1847,7 @@ static void mod_sysfs_teardown(struct module *mod)mod_sysfs_fini (mod); } -#ifdef CONFIG_DEBUG_SET_MODULE_RONX +#ifdef CONFIG_HARDENED_MODULE_MAPPINGS /* * LKM RO/NX protection: protect module's text/ro-data * from modification and any data from execution.
security/Kconfig +16 -0
@@ -174,6 +174,22 @@ config HARDENED_PAGE_MAPPINGS Unless your system has known restrictions or performance issues, it is recommended to say Y here. +config ARCH_HAS_HARDENED_MODULE_MAPPINGS + def_bool n + +config HARDENED_MODULE_MAPPINGS + bool "Mark module mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MODULE_MAPPINGS + 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 vulnerabilities (e.g. modifying + code) + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. + source security/selinux/Kconfig source security/smack/Kconfig source security/tomoyo/Kconfig
Signature · 1 line
2.7.4
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Laura AbbottQuoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_PAGE_MAPPINGSwhich more accurately describes what this option is intended to do.
I think this is bad change. CONFIG_DEBUG_RODATA is describing what it does, CONFIG_HARDENED_PAGE_MAPPINGS is advertising.
We don't do advertising, and we don't force people to re-answer the config questions without good reason.
CONFIG_HARDENED_RODATA might fix the first problem, but not the second one.
Pavel
Quoted 515 lines
Signed-off-by Laura Abbott <[email protected]>--- Documentation/DocBook/kgdb.tmpl | 8 ++++---- Documentation/security/self-protection.txt | 2 +- arch/arm/Kconfig | 1 + arch/arm/configs/aspeed_g4_defconfig | 2 +- arch/arm/configs/aspeed_g5_defconfig | 2 +- arch/arm/include/asm/cacheflush.h | 2 +- arch/arm/kernel/patch.c | 2 +- arch/arm/kernel/vmlinux.lds.S | 8 ++++---- arch/arm/mm/Kconfig | 14 +------------- arch/arm/mm/init.c | 4 ++-- arch/arm64/Kconfig | 4 +--- arch/arm64/Kconfig.debug | 2 +- arch/parisc/Kconfig | 1 + arch/parisc/Kconfig.debug | 11 ----------- arch/parisc/configs/712_defconfig | 2 +- arch/parisc/configs/c3000_defconfig | 2 +- arch/parisc/mm/init.c | 2 +- arch/s390/Kconfig | 4 +--- arch/x86/Kconfig | 4 +--- include/linux/init.h | 4 ++-- init/main.c | 4 ++-- kernel/configs/android-recommended.config | 2 +- kernel/power/hibernate.c | 2 +- kernel/power/power.h | 4 ++-- kernel/power/snapshot.c | 4 ++-- security/Kconfig | 16 ++++++++++++++++ 26 files changed, 51 insertions(+), 62 deletions(-)Documentation/DocBook/kgdb.tmpl +4
-4@@ -115,12 +115,12 @@ </para> <para> If the architecture that you are using supports the kernel option - CONFIG_DEBUG_RODATA, you should consider turning it off. This + CONFIG_HARDENED_PAGE_MAPPINGS, you should consider turning it off. This option will prevent the use of software breakpoints because it marks certain regions of the kernel's memory space as read-only. If kgdb supports it for the architecture you are using, you can use hardware breakpoints if you desire to run with the - CONFIG_DEBUG_RODATA option turned on, else you need to turn off + CONFIG_HARDENED_PAGE_MAPPINGS option turned on, else you need to turn off this option. </para> <para>@@ -135,7 +135,7 @@ <para>Here is an example set of .config symbols to enable or disable for kgdb: <itemizedlist> - <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para># CONFIG_HARDENED_PAGE_MAPPINGS is not set</para></listitem> <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> <listitem><para>CONFIG_KGDB=y</para></listitem> <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem>@@ -166,7 +166,7 @@ </para> <para>Here is an example set of .config symbols to enable/disable kdb: <itemizedlist> - <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para># CONFIG_HARDENED_PAGE_MAPPINGS is not set</para></listitem> <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> <listitem><para>CONFIG_KGDB=y</para></listitem> <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem>Documentation/security/self-protection.txt +1
-1@@ -51,7 +51,7 @@ kernel, they are implemented in a way where the memory is temporarily made writable during the update, and then returned to the original permissions.) -In support of this are (the poorly named) CONFIG_DEBUG_RODATA and +In support of this are CONFIG_HARDENED_PAGE_MAPPINGS and 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.arch/arm/Kconfig +1
-0@@ -7,6 +7,7 @@ config ARM select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_HARDENED_MAPPINGS if MMU && !XIP_KERNEL select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAParch/arm/configs/aspeed_g4_defconfig +1
-1@@ -25,7 +25,7 @@ CONFIG_MODULE_UNLOAD=y # CONFIG_ARCH_MULTI_V7 is not set CONFIG_ARCH_ASPEED=y CONFIG_MACH_ASPEED_G4=y -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_AEABI=y CONFIG_UACCESS_WITH_MEMCPY=y CONFIG_SECCOMP=yarch/arm/configs/aspeed_g5_defconfig +1
-1@@ -26,7 +26,7 @@ CONFIG_ARCH_MULTI_V6=y # CONFIG_ARCH_MULTI_V7 is not set CONFIG_ARCH_ASPEED=y CONFIG_MACH_ASPEED_G5=y -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_AEABI=y CONFIG_UACCESS_WITH_MEMCPY=y CONFIG_SECCOMP=yarch/arm/include/asm/cacheflush.h +1
-1@@ -490,7 +490,7 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; }#endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS void set_kernel_text_rw (void );void set_kernel_text_ro (void );#else arch/arm/kernel/patch.c +1
-1@@ -26,7 +26,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)if (module &&IS_ENABLED (CONFIG_DEBUG_SET_MODULE_RONX )) page =vmalloc_to_page (addr); -else if (!module &&IS_ENABLED (CONFIG_DEBUG_RODATA )) +else if (!module &&IS_ENABLED (CONFIG_HARDENED_PAGE_MAPPINGS )) page =virt_to_page (addr);else return addr;arch/arm/kernel/vmlinux.lds.S +4
-4@@ -97,7 +97,7 @@ SECTIONS HEAD_TEXT } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS . = ALIGN(1<<SECTION_SHIFT); #endif@@ -158,7 +158,7 @@ SECTIONS NOTES -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS . = ALIGN(1<<SECTION_SHIFT); #else . = ALIGN(PAGE_SIZE);@@ -230,7 +230,7 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) #endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS . = ALIGN(1<<SECTION_SHIFT); #else . = ALIGN(THREAD_SIZE);@@ -325,7 +325,7 @@ SECTIONS STABS_DEBUG } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS /* * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will * be the first section-aligned location after __start_rodata. Otherwise,arch/arm/mm/Kconfig +1
-13@@ -1051,21 +1051,9 @@ 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 + depends on HARDENED_PAGE_MAPPINGS default y help If this is set, rodata will be made explicitly non-executable. Thisarch/arm/mm/init.c +2
-2@@ -572,7 +572,7 @@ void __init mem_init(void) } } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS struct section_perm { const char *name; unsigned long start;@@ -741,7 +741,7 @@ void set_kernel_text_ro(void)#else static inline void fix_kernmem_perms (void ) { } -#endif /* CONFIG_DEBUG_RODATA */ +#endif /* CONFIG_HARDENED_PAGE_MAPPINGS */ void free_tcmmem (void ) {arch/arm64/Kconfig +1
-3@@ -11,6 +11,7 @@ config ARM64 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST@@ -123,9 +124,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_PAGESarch/arm64/Kconfig.debug +1
-1@@ -83,7 +83,7 @@ config DEBUG_SET_MODULE_RONX If in doubt, say Y. config DEBUG_ALIGN_RODATA - depends on DEBUG_RODATA + depends on ARCH_HAS_HARDENED_MAPPINGS bool "Align linker sections up to SECTION_SIZE" help If this option is enabled, sections that may potentially be marked asarch/parisc/Kconfig +1
-0@@ -8,6 +8,7 @@ config PARISC select HAVE_SYSCALL_TRACEPOINTS select ARCH_WANT_FRAME_POINTERS select ARCH_HAS_ELF_RANDOMIZE + select ARCH_HAS_HARDENED_MAPPINGS select RTC_CLASS select RTC_DRV_GENERIC select INIT_ALL_POSSIBLEarch/parisc/Kconfig.debug +0
-11@@ -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". - endmenuarch/parisc/configs/712_defconfig +1
-1@@ -182,7 +182,7 @@ CONFIG_DEBUG_FS=y CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_MUTEXES=y # CONFIG_RCU_CPU_STALL_DETECTOR is not set -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_CRYPTO_NULL=m CONFIG_CRYPTO_TEST=m CONFIG_CRYPTO_HMAC=yarch/parisc/configs/c3000_defconfig +1
-1@@ -166,7 +166,7 @@ CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_MUTEXES=y # CONFIG_DEBUG_BUGVERBOSE is not set # CONFIG_RCU_CPU_STALL_DETECTOR is not set -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_CRYPTO_NULL=m CONFIG_CRYPTO_TEST=m CONFIG_CRYPTO_MD5=march/parisc/mm/init.c +1
-1@@ -545,7 +545,7 @@ void free_initmem(void) } -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS void mark_rodata_ro (void ) {/* rodata memory was already mapped with KERNEL_RO access rights by arch/s390/Kconfig +1
-3@@ -62,15 +62,13 @@ 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 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_UBSAN_SANITIZE_ALLarch/x86/Kconfig +1
-3@@ -50,6 +50,7 @@ config X86 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV if X86_64 select ARCH_HAS_MMIO_FLUSH select ARCH_HAS_PMEM_API if X86_64@@ -309,9 +310,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_64include/linux/init.h +2
-2@@ -126,10 +126,10 @@ void prepare_namespace(void);void __init load_default_modules (void );int __init init_rootfs (void ); -#if defined(CONFIG_DEBUG_RODATA ) || defined(CONFIG_DEBUG_SET_MODULE_RONX ) +#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_DEBUG_SET_MODULE_RONX )extern bool rodata_enabled;#endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS void mark_rodata_ro (void );#endif init/main.c +2
-2@@ -925,7 +925,7 @@ static int try_to_run_init_process(const char *init_filename) static noinline void __init kernel_init_freeable(void); -#if defined(CONFIG_DEBUG_RODATA ) || defined(CONFIG_DEBUG_SET_MODULE_RONX ) +#if defined(CONFIG_HARDENED_PAGE_MAPPINGS ) || defined(CONFIG_DEBUG_SET_MODULE_RONX )bool rodata_enabled__ro_after_init = true;static int __init set_debug_rodata (char *str) {@@ -934,7 +934,7 @@ static int __init set_debug_rodata(char *str)__setup ("rodata=" , set_debug_rodata);#endif -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS static void mark_readonly (void ) {if (rodata_enabled)kernel/configs/android-recommended.config +1
-1@@ -11,7 +11,7 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=8192 CONFIG_COMPACTION=y -CONFIG_DEBUG_RODATA=y +CONFIG_HARDENED_PAGE_MAPPINGS=y CONFIG_DM_CRYPT=y CONFIG_DM_UEVENT=y CONFIG_DM_VERITY=ykernel/power/hibernate.c +1
-1@@ -1156,7 +1156,7 @@ static int __init hibernate_setup(char *str) }else if (!strncmp (str,"no" ,2 )) { noresume =1 ; nohibernate =1 ; - }else if (IS_ENABLED (CONFIG_DEBUG_RODATA ) + }else if (IS_ENABLED (CONFIG_HARDENED_PAGE_MAPPINGS ) && !strncmp (str,"protect_image" ,13 )) {enable_restore_image_protection (); }kernel/power/power.h +2
-2@@ -61,12 +61,12 @@ extern int hibernation_snapshot(int platform_mode);extern int hibernation_restore (int platform_mode);extern int hibernation_platform_enter (void ); -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS /* kernel/power/snapshot.c */ extern void enable_restore_image_protection (void );#else static inline void enable_restore_image_protection (void ) {} -#endif /* CONFIG_DEBUG_RODATA */ +#endif /* CONFIG_HARDENED_PAGE_MAPPINGS */ #else /* !CONFIG_HIBERNATION */ kernel/power/snapshot.c +2
-2@@ -38,7 +38,7 @@#include "power.h" -#ifdef CONFIG_DEBUG_RODATA +#ifdef CONFIG_HARDENED_PAGE_MAPPINGS static bool hibernate_restore_protection;static bool hibernate_restore_protection_active;@@ -73,7 +73,7 @@ static inline void hibernate_restore_protection_begin(void) {}static inline void hibernate_restore_protection_end (void ) {}static inline void hibernate_restore_protect_page (void *page_address) {}static inline void hibernate_restore_unprotect_page (void *page_address) {} -#endif /* CONFIG_DEBUG_RODATA */ +#endif /* CONFIG_HARDENED_PAGE_MAPPINGS */ static int swsusp_page_is_free (struct page *);static void swsusp_set_page_forbidden (struct page *);security/Kconfig +16
-0@@ -158,6 +158,22 @@ config HARDENED_USERCOPY_PAGESPAN been removed. This config is intended to be used only while trying to find such users. +config ARCH_HAS_HARDENED_MAPPINGS + def_bool n + +config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. + source security/selinux/Kconfig source security/smack/Kconfig source security/tomoyo/Kconfig
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Mark Rutland
reviewerRe: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Laura AbbottHi Laura,
Quoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_PAGE_MAPPINGSwhich more accurately describes what this option is intended to do.
This generally sounds good. Thanks for attacking this!
On the bikeshedding front, *maybe* it would be nice to mention permissions in the name, something like STRICT_KERNEL_RWX. That might also prevent the reading of 'hardened' as 'optional overhead'.
That said, the proposed name is fine by me -- I'm happy so long as 'DEBUG' goes.
Quoted 33 lines
arch/arm64/Kconfig +1
-3@@ -11,6 +11,7 @@ config ARM64 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_HARDENED_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST@@ -123,9 +124,6 @@ config ARCH_PHYS_ADDR_T_64BIT config MMU def_bool y -config DEBUG_RODATA - def_bool y -security/Kconfig +5
-0@@ -158,6 +158,22 @@ config HARDENED_USERCOPY_PAGESPAN been removed. This config is intended to be used only while trying to find such users. +config ARCH_HAS_HARDENED_MAPPINGS + def_bool n + +config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)"
security/Kconfig config HARDENED_USERCOPY_PAGESPAN · line 175
Quoted 10 lines
security/Kconfig +10
-0+ default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here.
It's somewhat unfortunate that this means the feature is no longer mandatory on arm64 (and s390+x86). We have a boot-time switch to turn the protections off, so I was hoping we could make this mandatory on all architectures with support.
It would be good to see if we could make this mandatory for arm and parisc, or if it really needs to be optional for either of those.
Thanks,
Mark.
Mark Rutland
reviewerRe: [PATCH 2/2] security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
In reply to Laura AbbottHi,
Quoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_SET_MODULE_RONX, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_MODULE_MAPPINGSwhich more accurately describes what this option is intended to do.
This looks good; my naming comments from the DEBUG_RODATA also apply here -- the proposed name is fine.
Quoted 38 lines
arch/arm64/Kconfig +1
-0@@ -12,6 +12,7 @@ config ARM64 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCASTarch/arm64/Kconfig.debug +6
-11@@ -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 ARCH_HAS_HARDENED_MODULE_MAPPINGS + def_bool n + +config HARDENED_MODULE_MAPPINGS + bool "Mark module mappings with stricter permissions (RO/W^X)" + default y
arch/arm64/Kconfig.debug config DEBUG_WX
Quoted 10 lines
arch/arm64/Kconfig.debug +10
-0+ depends on ARCH_HAS_HARDENED_MODULE_MAPPINGS + 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 vulnerabilities (e.g. modifying + code) + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. +
I was hoping that we'd make this mandatory, as we'd already done for DEBUG_RODATA.
Takahiro-san did a bit of work towards that in commit 39290b389ea2654f ("module: extend 'rodata=off' boot cmdline parameter to module mappings").
It would be good to know if there's any reason we can't do that.
Otherwise, this looks fine.
Thanks,
Mark.
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Mark RutlandQuoted 18 lines · Mark Rutland
security/Kconfig config HARDENED_USERCOPY_PAGESPAN · line 175
Quoted 12 lines
security/Kconfig +12
-0+config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here.It's somewhat unfortunate that this means the feature is no longer mandatory on arm64 (and s390+x86). We have a boot-time switch to turn the protections off, so I was hoping we could make this mandatory on all architectures with support.
Quoted 2 lines
It would be good to see if we could make this mandatory for arm and parisc, or if it really needs to be optional for either of those.
Looks like the config option is a no-op on parisc just like it is on s390. Irrelavant of the config option at least on s390 the page tables for kernel text and rodata will be read-only anyway.
This works since ages and I don't see a reason why this should be changed. Also trying to disable this with the "rodata=" command line option does not work at least on s390, and I guess this is true for parisc as well.
The only thing implemented with CONFIG_DEBUG_RODATA on both architectures is to emit a message that states memory has been protected (mark_rodata_ro).
This just avoids a wrong "Kernel memory protection disabled." message.
So yes, I'd really like to keep this option mandatory.
Re: [PATCH 2/2] security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
In reply to Mark RutlandQuoted 8 lines · Mark Rutland
Quoted 8 lines
security/Kconfig +8
-0+config HARDENED_MODULE_MAPPINGS + bool "Mark module mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MODULE_MAPPINGS + 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 vulnerabilities (e.g. modifying
Quoted 8 lines
security/Kconfig config HARDENED_PAGE_MAPPINGS · line 192
Quoted 5 lines
security/Kconfig +5
-0+ code) + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. +I was hoping that we'd make this mandatory, as we'd already done for
DEBUG_RODATA.
Same for s390: would be good to make this mandatory.
Re: [PATCH 2/2] security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
In reply to Laura AbbottHi Laura,
Quoted 8 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_SET_MODULE_RONX, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_MODULE_MAPPINGSwhich more accurately describes what this option is intended to do.Signed-off-by Laura Abbott <[email protected]>---
[...]
Quoted 34 lines
arch/arm/Kconfig +1
-0@@ -8,6 +8,7 @@ config ARM select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HARDENED_MAPPINGS if MMU && !XIP_KERNEL + select ARCH_HAS_HARDENED_MODULE_MAPPINGS if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAParch/arm/Kconfig.debug +0
-11@@ -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
[...]
Quoted 32 lines
arch/arm64/Kconfig +1
-0@@ -12,6 +12,7 @@ config ARM64 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCASTarch/arm64/Kconfig.debug +0
-11@@ -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 ARCH_HAS_HARDENED_MAPPINGS bool "Align linker sections up to SECTION_SIZE"
[...]
Quoted 56 lines
arch/s390/Kconfig +1
-0@@ -69,6 +69,7 @@ config S390 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_UBSAN_SANITIZE_ALLarch/s390/Kconfig.debug +0
-3@@ -17,7 +17,4 @@ config S390_PTDUMP kernel. If in doubt, say "N" -config DEBUG_SET_MODULE_RONX - def_bool y - depends on MODULES endmenuarch/x86/Kconfig +1
-0@@ -51,6 +51,7 @@ config X86 select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV if X86_64 select ARCH_HAS_MMIO_FLUSH select ARCH_HAS_PMEM_API if X86_64arch/x86/Kconfig.debug +0
-11@@ -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
[...]
security/Kconfig config HARDENED_PAGE_MAPPINGS · line 183
Quoted 13 lines
security/Kconfig +7
-0@@ -174,6 +174,22 @@ config HARDENED_PAGE_MAPPINGS Unless your system has known restrictions or performance issues, it is recommended to say Y here. +config ARCH_HAS_HARDENED_MODULE_MAPPINGS + def_bool n + +config HARDENED_MODULE_MAPPINGS + bool "Mark module mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MODULE_MAPPINGS
It would seem that this ends up losing the previous dependency on MODULES - is that intentional?
Robin.
Quoted 13 lines
security/Kconfig +9
-0+ 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 vulnerabilities (e.g. modifying + code) + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. + source security/selinux/Kconfig source security/smack/Kconfig source security/tomoyo/Kconfig
Helge Deller
maintainerRe: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Heiko CarstensQuoted 19 lines · Heiko Carstens
Quoted 18 lines · Mark Rutland
security/Kconfig config HARDENED_USERCOPY_PAGESPAN · line 175
Quoted 12 lines
security/Kconfig +12
-0+config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here.It's somewhat unfortunate that this means the feature is no longer mandatory on arm64 (and s390+x86). We have a boot-time switch to turn the protections off, so I was hoping we could make this mandatory on all architectures with support.
Quoted 6 lines
Quoted 2 lines
It would be good to see if we could make this mandatory for arm and parisc, or if it really needs to be optional for either of those.
Looks like the config option is a no-op on parisc just like it is on s390. Irrelavant of the config option at least on s390 the page tables for kernel text and rodata will be read-only anyway.
Right, that's true at the moment for parisc as well.
I do have unfinished patches which will add runtime kernel patching for ftrace to parisc, and those patches will need to add code to enable/disable ro text/data like x86.
Quoted 4 lines
This works since ages and I don't see a reason why this should be changed. Also trying to disable this with the "rodata=" command line option does not work at least on s390, and I guess this is true for parisc as well.
I never tried the option itself, but it should work on parisc to disable the ro protection by this option.
Quoted 6 lines
The only thing implemented with
CONFIG_DEBUG_RODATAon both architectures is to emit a message that states memory has been protected (mark_rodata_ro).
This just avoids a wrong "Kernel memory protection disabled." message.So yes, I'd really like to keep this option mandatory.
I'd be fine with a rename of the config option to ARCH_HAS_HARDENED_MAPPINGS and keeping the "rodata=" command line.
Helge
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Laura AbbottQuoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_PAGE_MAPPINGSwhich more accurately describes what this option is intended to do.
Oh thank you. Yes, this is badly needed. I might prefer to see this as two patches, though:
Move DEBUG_RODATA to top-level arch/Kconfig, (and add ARCH_HAS_[bikeshed]). Rename DEBUG_RODATA to [bikeshed]
(We should do a similar renaming for DEBUG_SET_MODULE_RONX too.)
Another thing that might be even cleaner would be to entirely invert the logic. Something like CONFIG_ARCH_MISSING_[bikeshed]?
Quoted 17 lines
arch/arm/Kconfig +1
-0@@ -7,6 +7,7 @@ config ARM select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_HARDENED_MAPPINGS if MMU && !XIP_KERNEL select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAParch/arm/mm/Kconfig +0
-0
arch/arm/mm/Kconfig config ARCH_SUPPORTS_BIG_ENDIAN · line 1057
Quoted 7 lines
arch/arm/mm/Kconfig +0
-4@@ -1051,21 +1051,9 @@ 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
These changes aren't correctly representing the ARM state. I think the ARCH_HAS is correct, but I'm not sure the best way to include the "default y if CPU_V7".
Quoted 15 lines
security/Kconfig +9
-0@@ -158,6 +158,22 @@ config HARDENED_USERCOPY_PAGESPAN been removed. This config is intended to be used only while trying to find such users. +config ARCH_HAS_HARDENED_MAPPINGS + def_bool n + +config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + help + If this is set, kernel text and rodata memory will be made read-only,
security/Kconfig config HARDENED_USERCOPY_PAGESPAN · line 179
Quoted 10 lines
security/Kconfig +7
-0+ and non-text memory will be made non-executable. This provides + protection against certain security attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here. + source security/selinux/Kconfig source security/smack/Kconfig source security/tomoyo/Kconfig
Should this go in arch/Kconfig or security/Kconfig? I'm starting to think we need a top-level kernel security Kconfig (the gcc plugins are starting to pile up in arch/Kconfig, for example). I think since this is arch specific, maybe arch/Kconfig? (Arguably, HARDENED_USERCOPY shouldn't be in security/Kconfig either, since security/Kconfig is mostly LSM or userspace-facing stuff? I dunno.)
As for the bikeshed on the naming, I like "KERNEL_RWX", and it likely doesn't need "STRICT", IMO. CONFIG_KERNEL_RWX ? I don't have a strong opinion beyond removing "DEBUG" from the name. :)
-Kees
Signature · 2 lines
Kees Cook Nexus Security
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Mark RutlandQuoted 23 lines · Mark Rutland
Hi Laura,
Quoted 20 lines · Laura Abbott
security/Kconfig +12
-0@@ -158,6 +158,22 @@ config HARDENED_USERCOPY_PAGESPAN been removed. This config is intended to be used only while trying to find such users. +config ARCH_HAS_HARDENED_MAPPINGS + def_bool n + +config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text).
Quoted 8 lines
security/Kconfig config HARDENED_USERCOPY_PAGESPAN · line 175
Quoted 3 lines
security/Kconfig +3
-0+ + Unless your system has known restrictions or performance issues, it + is recommended to say Y here.It's somewhat unfortunate that this means the feature is no longer mandatory on arm64 (and s390+x86). We have a boot-time switch to turn the protections off, so I was hoping we could make this mandatory on all architectures with support.
Oh, I totally missed this. Yes, we need it to stay mandatory. It should be possible by just adding "select HARDENED_PAGE_MAPPINGS" to the arch Kconfig, yes?
Quoted 2 lines
It would be good to see if we could make this mandatory for arm and parisc, or if it really needs to be optional for either of those.
(Adding mpe to CC...) Michael, what's needed to get this working on powerpc too?
-Kees
Signature · 2 lines
Kees Cook Nexus Security
Quoted 15 lines · Laura Abbott
Hi,
It's come up previously that
CONFIG_DEBUG_SET_MODULE_RONXandCONFIG_DEBUG_RODATAare not accurate names, mostly they should not have the word 'debug' in them. This series attempts to change the names to something a bit more descriptive and indicative of what they are actually used for these days.I marked this RFC for
- Bike shedding purposes.
- A discussion of what defaults should be. The way I did the refactoring, both options are default y. I'd appreciate comments if there is a better approach.
- Approach to split this up into more sub patches to make review/merging easier? Or maybe it's fine.
Quoted 8 lines
Quickly tested on arm/arm64/x86.
Thanks,
LauraLaura Abbott (2):
security: Change name ofCONFIG_DEBUG_RODATA
security: Change name ofCONFIG_DEBUG_SET_MODULE_RONX
Some day I'll quit reading my email backwards. :) I see you've got MODULE_RONX renamed too here, please ignore my comment about needing it "too". :)
-Kees
Signature · 2 lines
Kees Cook Nexus Security
kbuild test robot
build botRe: [PATCH 2/2] security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
In reply to Laura Abbotturl: https://github.com/0day-ci/linux/commits/Laura-Abbott/Better-hardening-names/20170119-200343 config: i386-randconfig-c0-01201130 (attached as .config) compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4…
Hi Laura,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.10-rc4]
[cannot apply to next-20170119]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Laura-Abbott/Better-hardening-names/20170119-200343
config: i386-randconfig-c0-01201130 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
arch/x86/built-in.o: In function `ftrace_arch_code_modify_prepare':
>> (.text+0x3fcb7): undefined reference to `set_all_modules_text_rw' arch/x86/built-in.o: In function `ftrace_arch_code_modify_post_process': >> (.text+0x3fcc3): undefined reference to `set_all_modules_text_ro'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Pavel MachekQuoted 10 lines · Pavel Machek
Quoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_PAGE_MAPPINGSwhich more accurately describes what this option is intended to do.I think this is bad change.
CONFIG_DEBUG_RODATAis describing what it does,CONFIG_HARDENED_PAGE_MAPPINGSis advertising.
Quoted 8 lines
We don't do advertising, and we don't force people to re-answer the config questions without good reason.
CONFIG_HARDENED_RODATAmight fix the first problem, but not the second one.Pavel
(Apologies, my SMTP was set up incorrectly so my response didn't actually get sent out)
CONFIG_DEBUG_RODATA isn't describing what it does though. It misses that this config may handle much more than just rodata. I think Mark Rutland's suggestion of STRICT_KERNEL_RWX might be more descriptive.
Thanks,
Laura
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Mark RutlandQuoted 9 lines · Mark Rutland
Hi Laura,
Quoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_PAGE_MAPPINGSwhich more accurately describes what this option is intended to do.
Quoted 9 lines
This generally sounds good. Thanks for attacking this!
On the bikeshedding front, *maybe* it would be nice to mention permissions in the name, something like
STRICT_KERNEL_RWX. That might also prevent the reading of 'hardened' as 'optional overhead'.That said, the proposed name is fine by me -- I'm happy so long as 'DEBUG' goes.
(Apologies for the delay, my SMTP was set up incorrectly so my messages didn't actually get sent out)
I like that better since it's describing specifically what the config should be setting as opposed to something more vague. That might fit better with what Pavel was suggesting as well.
Thanks,
Laura
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Heiko CarstensQuoted 31 lines · Heiko Carstens
Quoted 18 lines · Mark Rutland
security/Kconfig config HARDENED_USERCOPY_PAGESPAN · line 175
Quoted 12 lines
security/Kconfig +12
-0+config HARDENED_PAGE_MAPPINGS + bool "Mark kernel mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MAPPINGS + 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 attacks (e.g. executing the heap + or modifying text). + + Unless your system has known restrictions or performance issues, it + is recommended to say Y here.It's somewhat unfortunate that this means the feature is no longer mandatory on arm64 (and s390+x86). We have a boot-time switch to turn the protections off, so I was hoping we could make this mandatory on all architectures with support.
Quoted 2 lines
It would be good to see if we could make this mandatory for arm and parisc, or if it really needs to be optional for either of those.
Looks like the config option is a no-op on parisc just like it is on s390. Irrelavant of the config option at least on s390 the page tables for kernel text and rodata will be read-only anyway.
This works since ages and I don't see a reason why this should be changed. Also trying to disable this with the "rodata=" command line option does not work at least on s390, and I guess this is true for parisc as well.
Quoted 7 lines
The only thing implemented with
CONFIG_DEBUG_RODATAon both architectures is to emit a message that states memory has been protected (mark_rodata_ro).
This just avoids a wrong "Kernel memory protection disabled." message.So yes, I'd really like to keep this option mandatory.
(Apologies, my SMTP server was set up incorrectly so this didn't get sent out when I thought it did)
Okay, that's useful to know. I think I'm going to add a 'select HARDENED_MAPPINGS' (or whatever it gets changed to) to arches that were previously def_bool. This is a slight Kconfig semantic change but as has been pointed out we now have the command line option.
Thanks,
Laura
Re: [PATCH 2/2] security: Change name of CONFIG_DEBUG_SET_MODULE_RONX
In reply to Robin MurphyQuoted 162 lines · Robin Murphy
Hi Laura,
Quoted 8 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_SET_MODULE_RONX, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_MODULE_MAPPINGSwhich more accurately describes what this option is intended to do.Signed-off-by Laura Abbott <[email protected]>---
[...]
Quoted 34 lines
arch/arm/Kconfig +1
-0@@ -8,6 +8,7 @@ config ARM select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HARDENED_MAPPINGS if MMU && !XIP_KERNEL + select ARCH_HAS_HARDENED_MODULE_MAPPINGS if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAParch/arm/Kconfig.debug +0
-11@@ -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[...]
Quoted 32 lines
arch/arm64/Kconfig +1
-0@@ -12,6 +12,7 @@ config ARM64 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCASTarch/arm64/Kconfig.debug +0
-11@@ -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 ARCH_HAS_HARDENED_MAPPINGS bool "Align linker sections up to SECTION_SIZE"[...]
Quoted 56 lines
arch/s390/Kconfig +1
-0@@ -69,6 +69,7 @@ config S390 select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV select ARCH_HAS_SG_CHAIN select ARCH_HAS_UBSAN_SANITIZE_ALLarch/s390/Kconfig.debug +0
-3@@ -17,7 +17,4 @@ config S390_PTDUMP kernel. If in doubt, say "N" -config DEBUG_SET_MODULE_RONX - def_bool y - depends on MODULES endmenuarch/x86/Kconfig +1
-0@@ -51,6 +51,7 @@ config X86 select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_HARDENED_MAPPINGS + select ARCH_HAS_HARDENED_MODULE_MAPPINGS select ARCH_HAS_KCOV if X86_64 select ARCH_HAS_MMIO_FLUSH select ARCH_HAS_PMEM_API if X86_64arch/x86/Kconfig.debug +0
-11@@ -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[...]
security/Kconfig config HARDENED_PAGE_MAPPINGS · line 183
Quoted 13 lines
security/Kconfig +7
-0@@ -174,6 +174,22 @@ config HARDENED_PAGE_MAPPINGS Unless your system has known restrictions or performance issues, it is recommended to say Y here. +config ARCH_HAS_HARDENED_MODULE_MAPPINGS + def_bool n + +config HARDENED_MODULE_MAPPINGS + bool "Mark module mappings with stricter permissions (RO/W^X)" + default y + depends on ARCH_HAS_HARDENED_MODULE_MAPPINGSIt would seem that this ends up losing the previous dependency on MODULES - is that intentional?
Quoted 2 lines
Robin.
(Apologies, my SMTP was set up incorrectly so this didn't actually get sent out when I thought it did)
No, good catch. I missed re-adding that when doing the refactoring.
Thanks,
Laura
Quoted 2 lines
Quoted 1 line
Re: [PATCH 1/2] security: Change name of CONFIG_DEBUG_RODATA
In reply to Laura AbbottQuoted 20 lines · Laura Abbott
Quoted 10 lines · Pavel Machek
Quoted 5 lines · Laura Abbott
Despite the word 'debug' in
CONFIG_DEBUG_RODATA, this kernel option provides key security features that are to be expected on a modern system. Change the name toCONFIG_HARDENED_PAGE_MAPPINGSwhich more accurately describes what this option is intended to do.I think this is bad change.
CONFIG_DEBUG_RODATAis describing what it does,CONFIG_HARDENED_PAGE_MAPPINGSis advertising.Quoted 8 lines
We don't do advertising, and we don't force people to re-answer the config questions without good reason.
CONFIG_HARDENED_RODATAmight fix the first problem, but not the second one.Pavel
Quoted 7 lines
(Apologies, my SMTP was set up incorrectly so my response didn't actually get sent out)
CONFIG_DEBUG_RODATAisn't describing what it does though. It misses that this config may handle much more than just rodata. I think Mark Rutland's suggestion ofSTRICT_KERNEL_RWXmight be more descriptive.
CONFIG_BUG=yCONFIG_LBDAF=yCONFIG_PM_OPP=y
..it is config option. It is not description of the feature. People are living with that config option for a while. I'd keep it.
Maybe you can go from CONFIG_DEBUG_RODATA to CONFIG_RODATA... (but you'll still have people re-answer config option.)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html