You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge tag 'rodata-v4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull rodata updates from Kees Cook: "This renames the (now inaccurate) DEBUG_RODATA and related SET_MODULE_RONX configs to the more sensible STRICT_KERNEL_RWX and STRICT_MODULE_RWX" * tag 'rodata-v4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: arch: Rename CONFIG_DEBUG_RODATA and CONFIG_DEBUG_MODULE_RONX arch: Move CONFIG_DEBUG_RODATA and CONFIG_SET_MODULE_RONX to be common
This commit is contained in:
@@ -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_STRICT_KERNEL_RWX, 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_STRICT_KERNEL_RWX 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_STRICT_KERNEL_RWX 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_STRICT_KERNEL_RWX 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>
|
||||
|
||||
@@ -51,11 +51,17 @@ 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
|
||||
CONFIG_DEBUG_SET_MODULE_RONX, which seek to make sure that code is not
|
||||
In support of this are CONFIG_STRICT_KERNEL_RWX and
|
||||
CONFIG_STRICT_MODULE_RWX, 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
|
||||
|
||||
@@ -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 STRICT_KERNEL_RWX
|
||||
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 STRICT_MODULE_RWX
|
||||
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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,7 +25,6 @@ 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_AEABI=y
|
||||
CONFIG_UACCESS_WITH_MEMCPY=y
|
||||
CONFIG_SECCOMP=y
|
||||
@@ -79,7 +78,8 @@ 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_STRICT_MODULE_RWX=y
|
||||
CONFIG_STRICT_KERNEL_RWX=y
|
||||
# CONFIG_XZ_DEC_X86 is not set
|
||||
# CONFIG_XZ_DEC_POWERPC is not set
|
||||
# CONFIG_XZ_DEC_IA64 is not set
|
||||
|
||||
@@ -26,7 +26,6 @@ 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_AEABI=y
|
||||
CONFIG_UACCESS_WITH_MEMCPY=y
|
||||
CONFIG_SECCOMP=y
|
||||
@@ -81,7 +80,8 @@ 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_STRICT_MODULE_RWX=y
|
||||
CONFIG_STRICT_KERNEL_RWX=y
|
||||
# CONFIG_XZ_DEC_X86 is not set
|
||||
# CONFIG_XZ_DEC_POWERPC is not set
|
||||
# CONFIG_XZ_DEC_IA64 is not set
|
||||
|
||||
@@ -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_STRICT_KERNEL_RWX
|
||||
void set_kernel_text_rw(void);
|
||||
void set_kernel_text_ro(void);
|
||||
#else
|
||||
|
||||
@@ -24,9 +24,9 @@ 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_STRICT_MODULE_RWX))
|
||||
page = vmalloc_to_page(addr);
|
||||
else if (!module && IS_ENABLED(CONFIG_DEBUG_RODATA))
|
||||
else if (!module && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
|
||||
page = virt_to_page(addr);
|
||||
else
|
||||
return addr;
|
||||
|
||||
@@ -97,7 +97,7 @@ SECTIONS
|
||||
HEAD_TEXT
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_RODATA
|
||||
#ifdef CONFIG_STRICT_KERNEL_RWX
|
||||
. = ALIGN(1<<SECTION_SHIFT);
|
||||
#endif
|
||||
|
||||
@@ -158,7 +158,7 @@ SECTIONS
|
||||
|
||||
NOTES
|
||||
|
||||
#ifdef CONFIG_DEBUG_RODATA
|
||||
#ifdef CONFIG_STRICT_KERNEL_RWX
|
||||
. = 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_STRICT_KERNEL_RWX
|
||||
. = ALIGN(1<<SECTION_SHIFT);
|
||||
#else
|
||||
. = ALIGN(THREAD_SIZE);
|
||||
@@ -325,7 +325,7 @@ SECTIONS
|
||||
STABS_DEBUG
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_RODATA
|
||||
#ifdef CONFIG_STRICT_KERNEL_RWX
|
||||
/*
|
||||
* Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
|
||||
* be the first section-aligned location after __start_rodata. Otherwise,
|
||||
|
||||
+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 STRICT_KERNEL_RWX
|
||||
default y
|
||||
help
|
||||
If this is set, rodata will be made explicitly non-executable. This
|
||||
|
||||
+2
-2
@@ -572,7 +572,7 @@ void __init mem_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_RODATA
|
||||
#ifdef CONFIG_STRICT_KERNEL_RWX
|
||||
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_STRICT_KERNEL_RWX */
|
||||
|
||||
void free_tcmmem(void)
|
||||
{
|
||||
|
||||
+2
-3
@@ -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
|
||||
|
||||
@@ -71,19 +71,8 @@ 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
|
||||
depends on STRICT_KERNEL_RWX
|
||||
bool "Align linker sections up to SECTION_SIZE"
|
||||
help
|
||||
If this option is enabled, sections that may potentially be marked as
|
||||
|
||||
@@ -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_STRICT_MODULE_RWX))
|
||||
page = vmalloc_to_page(addr);
|
||||
else if (!module)
|
||||
page = pfn_to_page(PHYS_PFN(__pa(addr)));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -182,7 +182,6 @@ 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_CRYPTO_NULL=m
|
||||
CONFIG_CRYPTO_TEST=m
|
||||
CONFIG_CRYPTO_HMAC=y
|
||||
|
||||
@@ -166,7 +166,6 @@ 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_CRYPTO_NULL=m
|
||||
CONFIG_CRYPTO_TEST=m
|
||||
CONFIG_CRYPTO_MD5=m
|
||||
|
||||
@@ -545,7 +545,7 @@ void free_initmem(void)
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_DEBUG_RODATA
|
||||
#ifdef CONFIG_STRICT_KERNEL_RWX
|
||||
void mark_rodata_ro(void)
|
||||
{
|
||||
/* rodata memory was already mapped with KERNEL_RO access rights by
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user