···1313assert (versionAtLeast version "4.9");
14141515''
1616-GCC_PLUGINS y # Enable gcc plugin options
1616+# Report BUG() conditions and kill the offending process.
1717+BUG y
1818+1919+${optionalString (stdenv.system == "x86_64-linux") ''
2020+ DEFAULT_MMAP_MIN_ADDR 65536 # Prevent allocation of first 64K of memory
2121+2222+ # Reduce attack surface by disabling various emulations
2323+ IA32_EMULATION n
2424+ X86_X32 n
2525+ MODIFY_LDT_SYSCALL n
2626+2727+ VMAP_STACK y # Catch kernel stack overflows
2828+2929+ # Randomize position of kernel and memory.
3030+ RANDOMIZE_BASE y
3131+ RANDOMIZE_MEMORY y
3232+3333+ # Modern libc no longer needs a fixed-position mapping in userspace, remove it as a possible target.
3434+ LEGACY_VSYSCALL_NONE y
3535+''}
3636+3737+# Make sure kernel page tables have safe permissions.
3838+DEBUG_KERNEL y
3939+4040+${optionalString (versionOlder version "4.11") ''
4141+ DEBUG_RODATA y
4242+ DEBUG_SET_MODULE_RONX y
4343+''}
17441845${optionalString (versionAtLeast version "4.11") ''
1946 GCC_PLUGIN_STRUCTLEAK y # A port of the PaX structleak plugin
2047''}
21482222-DEBUG_WX y # A one-time check for W+X mappings at boot; doesn't do anything beyond printing a warning
4949+# Report any dangerous memory permissions (not available on all archs).
5050+DEBUG_WX y
23512424-${optionalString (versionAtLeast version "4.10") ''
2525- BUG_ON_DATA_CORRUPTION y # BUG if kernel struct validation detects corruption
2626-''}
5252+# Do not allow direct physical memory access (but if you must have it, at least enable STRICT mode...)
5353+# DEVMEM is not set
5454+STRICT_DEVMEM y
5555+IO_STRICT_DEVMEM y
27562828-# Additional validation of commonly targetted structures
5757+# Perform additional validation of various commonly targeted structures.
2958DEBUG_CREDENTIALS y
3059DEBUG_NOTIFIERS y
3160DEBUG_LIST y
3261DEBUG_SG y
6262+BUG_ON_DATA_CORRUPTION y
6363+SCHED_STACK_END_CHECK y
33643434-HARDENED_USERCOPY y # Bounds check usercopy
6565+# Provide userspace with seccomp BPF API for syscall attack surface reduction.
6666+SECCOMP y
6767+SECCOMP_FILTER y
6868+6969+# Provide userspace with ptrace ancestry protections.
7070+SECURITY y
7171+SECURITY_YAMA y
7272+7373+# Perform usercopy bounds checking.
7474+HARDENED_USERCOPY y
7575+7676+# Randomize allocator freelists.
7777+SLAB_FREELIST_RANDOM y
35783636-# Wipe on free with page_poison=1
7979+# Wipe higher-level memory allocations when they are freed (needs "page_poison 1" command line below).
8080+# (If you can afford even more performance penalty, leave PAGE_POISONING_NO_SANITY n)
3781PAGE_POISONING y
3882PAGE_POISONING_NO_SANITY y
3983PAGE_POISONING_ZERO y
40844141-CC_STACKPROTECTOR_REGULAR n
4242-CC_STACKPROTECTOR_STRONG y
8585+# Reboot devices immediately if kernel experiences an Oops.
8686+PANIC_ON_OOPS y
8787+PANIC_TIMEOUT -1
43884444-# Stricter /dev/mem
4545-STRICT_DEVMEM y
4646-IO_STRICT_DEVMEM y
8989+# Keep root from altering kernel memory via loadable modules.
9090+# MODULES is not set
9191+9292+GCC_PLUGINS y # Enable gcc plugin options
47934894# Disable various dangerous settings
4995ACPI_CUSTOM_METHOD n # Allows writing directly to physical memory
5096PROC_KCORE n # Exposes kernel text image layout
5197INET_DIAG n # Has been used for heap based attacks in the past
52985353-${optionalString (stdenv.system == "x86_64-linux") ''
5454- DEFAULT_MMAP_MIN_ADDR 65536 # Prevent allocation of first 64K of memory
5555-5656- # Reduce attack surface by disabling various emulations
5757- IA32_EMULATION n
5858- X86_X32 n
5959-6060- VMAP_STACK y # Catch kernel stack overflows
6161-''}
6262-9999+# Use -fstack-protector-strong (gcc 4.9+) for best stack canary coverage.
100100+CC_STACKPROTECTOR_REGULAR n
101101+CC_STACKPROTECTOR_STRONG y
63102''