3 # N.B. Hardening sysctls:
4 # kernel.kptr_restrict=2 (or 1?)
5 # kernel.dmesg_restrict=1 (also see the kconfig option)
6 # kernel.perf_event_paranoid=2 (or 3 with a custom patch, see https://lwn.net/Articles/696216/)
7 # kernel.kexec_load_disabled=1
8 # kernel.yama.ptrace_scope=3
9 # user.max_user_namespaces=0
10 # what about bpf_jit_enable?
11 # kernel.unprivileged_bpf_disabled=1
12 # net.core.bpf_jit_harden=2
13 # vm.unprivileged_userfaultfd=0
14 # (at first, it disabled unprivileged userfaultfd,
15 # and since v5.11 it enables unprivileged userfaultfd for user-mode only)
16 # vm.mmap_min_addr has a good value
17 # dev.tty.ldisc_autoload=0
18 # fs.protected_symlinks=1
19 # fs.protected_hardlinks=1
20 # fs.protected_fifos=2
21 # fs.protected_regular=2
23 # kernel.modules_disabled=1
24 # kernel.randomize_va_space = 2
25 # nosmt sysfs control file
27 # Think of these boot params:
28 # module.sig_enforce=1
29 # lockdown=confidentiality
34 # efi=disable_early_pci_dma
36 # pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
37 # pylint: disable=line-too-long,invalid-name,too-many-branches,too-many-statements
39 from .engine import KconfigCheck, CmdlineCheck, VersionCheck, OR, AND
42 def add_kconfig_checks(l, arch):
43 # Calling the KconfigCheck class constructor:
44 # KconfigCheck(reason, decision, name, expected)
46 # [!] Don't add CmdlineChecks in add_kconfig_checks() to avoid wrong results
47 # when the tool doesn't check the cmdline.
49 efi_not_set = KconfigCheck('-', '-', 'EFI', 'is not set')
50 cc_is_gcc = KconfigCheck('-', '-', 'CC_IS_GCC', 'y') # exists since v4.18
51 cc_is_clang = KconfigCheck('-', '-', 'CC_IS_CLANG', 'y') # exists since v4.18
53 modules_not_set = KconfigCheck('cut_attack_surface', 'kspp', 'MODULES', 'is not set')
54 devmem_not_set = KconfigCheck('cut_attack_surface', 'kspp', 'DEVMEM', 'is not set') # refers to LOCKDOWN
55 bpf_syscall_not_set = KconfigCheck('cut_attack_surface', 'lockdown', 'BPF_SYSCALL', 'is not set') # refers to LOCKDOWN
57 # 'self_protection', 'defconfig'
58 l += [KconfigCheck('self_protection', 'defconfig', 'BUG', 'y')]
59 l += [KconfigCheck('self_protection', 'defconfig', 'SLUB_DEBUG', 'y')]
60 l += [KconfigCheck('self_protection', 'defconfig', 'THREAD_INFO_IN_TASK', 'y')]
61 gcc_plugins_support_is_set = KconfigCheck('self_protection', 'defconfig', 'GCC_PLUGINS', 'y')
62 l += [gcc_plugins_support_is_set]
63 iommu_support_is_set = KconfigCheck('self_protection', 'defconfig', 'IOMMU_SUPPORT', 'y')
64 l += [iommu_support_is_set] # is needed for mitigating DMA attacks
65 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR', 'y'),
66 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR', 'y'),
67 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_REGULAR', 'y'),
68 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_AUTO', 'y'),
69 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_STRONG', 'y'))]
70 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR_STRONG', 'y'),
71 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_STRONG', 'y'))]
72 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STRICT_KERNEL_RWX', 'y'),
73 KconfigCheck('self_protection', 'defconfig', 'DEBUG_RODATA', 'y'))] # before v4.11
74 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STRICT_MODULE_RWX', 'y'),
75 KconfigCheck('self_protection', 'defconfig', 'DEBUG_SET_MODULE_RONX', 'y'),
76 modules_not_set)] # DEBUG_SET_MODULE_RONX was before v4.11
77 l += [OR(KconfigCheck('self_protection', 'defconfig', 'REFCOUNT_FULL', 'y'),
78 VersionCheck((5, 5)))] # REFCOUNT_FULL is enabled by default since v5.5
79 if arch in ('X86_64', 'ARM64', 'X86_32'):
80 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_BASE', 'y')]
81 if arch in ('X86_64', 'ARM64', 'ARM'):
82 l += [KconfigCheck('self_protection', 'defconfig', 'VMAP_STACK', 'y')]
83 if arch in ('X86_64', 'X86_32'):
84 l += [KconfigCheck('self_protection', 'defconfig', 'DEBUG_WX', 'y')]
85 l += [KconfigCheck('self_protection', 'defconfig', 'WERROR', 'y')]
86 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE', 'y')]
87 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE_INTEL', 'y')]
88 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE_AMD', 'y')]
89 l += [KconfigCheck('self_protection', 'defconfig', 'MICROCODE', 'y')] # is needed for mitigating CPU bugs
90 l += [KconfigCheck('self_protection', 'defconfig', 'RETPOLINE', 'y')]
91 l += [KconfigCheck('self_protection', 'defconfig', 'SYN_COOKIES', 'y')] # another reason?
92 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_SMAP', 'y'),
93 VersionCheck((5, 19)))] # X86_SMAP is enabled by default since v5.19
94 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_UMIP', 'y'),
95 KconfigCheck('self_protection', 'defconfig', 'X86_INTEL_UMIP', 'y'))]
96 if arch in ('ARM64', 'ARM'):
97 l += [KconfigCheck('self_protection', 'defconfig', 'IOMMU_DEFAULT_DMA_STRICT', 'y')]
98 l += [KconfigCheck('self_protection', 'defconfig', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set')] # true if IOMMU_DEFAULT_DMA_STRICT is set
99 l += [KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR_PER_TASK', 'y')]
101 l += [KconfigCheck('self_protection', 'defconfig', 'PAGE_TABLE_ISOLATION', 'y')]
102 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_MEMORY', 'y')]
103 l += [AND(KconfigCheck('self_protection', 'defconfig', 'INTEL_IOMMU', 'y'),
104 iommu_support_is_set)]
105 l += [AND(KconfigCheck('self_protection', 'defconfig', 'AMD_IOMMU', 'y'),
106 iommu_support_is_set)]
108 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_PAN', 'y')]
109 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_EPAN', 'y')]
110 l += [KconfigCheck('self_protection', 'defconfig', 'UNMAP_KERNEL_AT_EL0', 'y')]
111 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_E0PD', 'y')]
112 l += [KconfigCheck('self_protection', 'defconfig', 'RODATA_FULL_DEFAULT_ENABLED', 'y')]
113 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_PTR_AUTH_KERNEL', 'y')]
114 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_BTI_KERNEL', 'y')]
115 l += [KconfigCheck('self_protection', 'defconfig', 'MITIGATE_SPECTRE_BRANCH_HISTORY', 'y')]
116 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_MTE', 'y')]
117 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_MODULE_REGION_FULL', 'y')]
118 l += [OR(KconfigCheck('self_protection', 'defconfig', 'HARDEN_EL2_VECTORS', 'y'),
119 AND(KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_BASE', 'y'),
120 VersionCheck((5, 9))))] # HARDEN_EL2_VECTORS was included in RANDOMIZE_BASE in v5.9
121 l += [OR(KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_PREDICTOR', 'y'),
122 VersionCheck((5, 10)))] # HARDEN_BRANCH_PREDICTOR is enabled by default since v5.10
124 l += [KconfigCheck('self_protection', 'defconfig', 'CPU_SW_DOMAIN_PAN', 'y')]
125 l += [KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_PREDICTOR', 'y')]
126 l += [KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_HISTORY', 'y')]
128 # 'self_protection', 'kspp'
129 l += [KconfigCheck('self_protection', 'kspp', 'BUG_ON_DATA_CORRUPTION', 'y')]
130 l += [KconfigCheck('self_protection', 'kspp', 'SCHED_STACK_END_CHECK', 'y')]
131 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_FREELIST_HARDENED', 'y')]
132 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_FREELIST_RANDOM', 'y')]
133 l += [KconfigCheck('self_protection', 'kspp', 'SHUFFLE_PAGE_ALLOCATOR', 'y')]
134 l += [KconfigCheck('self_protection', 'kspp', 'FORTIFY_SOURCE', 'y')]
135 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_LIST', 'y')]
136 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_VIRTUAL', 'y')]
137 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_SG', 'y')]
138 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_CREDENTIALS', 'y')]
139 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_NOTIFIERS', 'y')]
140 l += [KconfigCheck('self_protection', 'kspp', 'INIT_ON_ALLOC_DEFAULT_ON', 'y')]
141 l += [KconfigCheck('self_protection', 'kspp', 'KFENCE', 'y')]
142 l += [KconfigCheck('self_protection', 'kspp', 'ZERO_CALL_USED_REGS', 'y')]
143 l += [KconfigCheck('self_protection', 'kspp', 'HW_RANDOM_TPM', 'y')]
144 l += [KconfigCheck('self_protection', 'kspp', 'STATIC_USERMODEHELPER', 'y')] # needs userspace support
145 randstruct_is_set = OR(KconfigCheck('self_protection', 'kspp', 'RANDSTRUCT_FULL', 'y'),
146 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_RANDSTRUCT', 'y'))
147 l += [randstruct_is_set]
148 l += [AND(KconfigCheck('self_protection', 'kspp', 'RANDSTRUCT_PERFORMANCE', 'is not set'),
149 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_RANDSTRUCT_PERFORMANCE', 'is not set'),
151 hardened_usercopy_is_set = KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY', 'y')
152 l += [hardened_usercopy_is_set]
153 l += [AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_FALLBACK', 'is not set'),
154 hardened_usercopy_is_set)]
155 l += [AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_PAGESPAN', 'is not set'),
156 hardened_usercopy_is_set)]
157 l += [AND(KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_LATENT_ENTROPY', 'y'),
158 gcc_plugins_support_is_set)]
159 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG', 'y'),
161 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_ALL', 'y'),
163 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_SHA512', 'y'),
165 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_FORCE', 'y'),
166 modules_not_set)] # refers to LOCKDOWN
167 l += [OR(KconfigCheck('self_protection', 'kspp', 'INIT_STACK_ALL_ZERO', 'y'),
168 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STRUCTLEAK_BYREF_ALL', 'y'))]
169 l += [OR(KconfigCheck('self_protection', 'kspp', 'INIT_ON_FREE_DEFAULT_ON', 'y'),
170 KconfigCheck('self_protection', 'kspp', 'PAGE_POISONING_ZERO', 'y'))]
171 # CONFIG_INIT_ON_FREE_DEFAULT_ON was added in v5.3.
172 # CONFIG_PAGE_POISONING_ZERO was removed in v5.11.
173 # Starting from v5.11 CONFIG_PAGE_POISONING unconditionally checks
174 # the 0xAA poison pattern on allocation.
175 # That brings higher performance penalty.
176 l += [OR(KconfigCheck('self_protection', 'kspp', 'EFI_DISABLE_PCI_DMA', 'y'),
178 l += [OR(KconfigCheck('self_protection', 'kspp', 'RESET_ATTACK_MITIGATION', 'y'),
179 efi_not_set)] # needs userspace support (systemd)
180 ubsan_bounds_is_set = KconfigCheck('self_protection', 'kspp', 'UBSAN_BOUNDS', 'y')
181 l += [ubsan_bounds_is_set]
182 l += [OR(KconfigCheck('self_protection', 'kspp', 'UBSAN_LOCAL_BOUNDS', 'y'),
183 AND(ubsan_bounds_is_set,
185 l += [AND(KconfigCheck('self_protection', 'kspp', 'UBSAN_TRAP', 'y'),
187 KconfigCheck('self_protection', 'kspp', 'UBSAN_SHIFT', 'is not set'),
188 KconfigCheck('self_protection', 'kspp', 'UBSAN_DIV_ZERO', 'is not set'),
189 KconfigCheck('self_protection', 'kspp', 'UBSAN_UNREACHABLE', 'is not set'),
190 KconfigCheck('self_protection', 'kspp', 'UBSAN_BOOL', 'is not set'),
191 KconfigCheck('self_protection', 'kspp', 'UBSAN_ENUM', 'is not set'),
192 KconfigCheck('self_protection', 'kspp', 'UBSAN_ALIGNMENT', 'is not set'))] # only array index bounds checking with traps
193 if arch in ('X86_64', 'ARM64', 'X86_32'):
194 l += [AND(KconfigCheck('self_protection', 'kspp', 'UBSAN_SANITIZE_ALL', 'y'),
195 ubsan_bounds_is_set)] # ARCH_HAS_UBSAN_SANITIZE_ALL is not enabled for ARM
196 stackleak_is_set = KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STACKLEAK', 'y')
197 l += [AND(stackleak_is_set, gcc_plugins_support_is_set)]
198 l += [AND(KconfigCheck('self_protection', 'kspp', 'STACKLEAK_METRICS', 'is not set'),
200 gcc_plugins_support_is_set)]
201 l += [AND(KconfigCheck('self_protection', 'kspp', 'STACKLEAK_RUNTIME_DISABLE', 'is not set'),
203 gcc_plugins_support_is_set)]
204 l += [KconfigCheck('self_protection', 'kspp', 'RANDOMIZE_KSTACK_OFFSET_DEFAULT', 'y')]
205 if arch in ('X86_64', 'ARM64'):
206 cfi_clang_is_set = KconfigCheck('self_protection', 'kspp', 'CFI_CLANG', 'y')
207 l += [cfi_clang_is_set]
208 l += [AND(KconfigCheck('self_protection', 'kspp', 'CFI_PERMISSIVE', 'is not set'),
210 if arch in ('X86_64', 'X86_32'):
211 l += [KconfigCheck('self_protection', 'kspp', 'SCHED_CORE', 'y')]
212 l += [KconfigCheck('self_protection', 'kspp', 'DEFAULT_MMAP_MIN_ADDR', '65536')]
213 l += [KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y')]
214 l += [KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set')] # true if IOMMU_DEFAULT_DMA_STRICT is set
215 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU_DEFAULT_ON', 'y'),
216 iommu_support_is_set)]
217 if arch in ('ARM64', 'ARM'):
218 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_WX', 'y')]
219 l += [KconfigCheck('self_protection', 'kspp', 'WERROR', 'y')]
220 l += [KconfigCheck('self_protection', 'kspp', 'DEFAULT_MMAP_MIN_ADDR', '32768')]
221 l += [KconfigCheck('self_protection', 'kspp', 'SYN_COOKIES', 'y')] # another reason?
223 l += [KconfigCheck('self_protection', 'kspp', 'SLS', 'y')] # vs CVE-2021-26341 in Straight-Line-Speculation
224 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU_SVM', 'y'),
225 iommu_support_is_set)]
226 l += [AND(KconfigCheck('self_protection', 'kspp', 'AMD_IOMMU_V2', 'y'),
227 iommu_support_is_set)]
229 l += [KconfigCheck('self_protection', 'kspp', 'ARM64_SW_TTBR0_PAN', 'y')]
230 l += [KconfigCheck('self_protection', 'kspp', 'SHADOW_CALL_STACK', 'y')]
231 l += [KconfigCheck('self_protection', 'kspp', 'KASAN_HW_TAGS', 'y')] # see also: kasan=on, kasan.stacktrace=off, kasan.fault=panic
233 l += [KconfigCheck('self_protection', 'kspp', 'PAGE_TABLE_ISOLATION', 'y')]
234 l += [KconfigCheck('self_protection', 'kspp', 'HIGHMEM64G', 'y')]
235 l += [KconfigCheck('self_protection', 'kspp', 'X86_PAE', 'y')]
236 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU', 'y'),
237 iommu_support_is_set)]
239 # 'self_protection', 'clipos'
240 l += [KconfigCheck('self_protection', 'clipos', 'SLAB_MERGE_DEFAULT', 'is not set')]
243 if arch in ('X86_64', 'ARM64', 'X86_32'):
244 l += [KconfigCheck('security_policy', 'defconfig', 'SECURITY', 'y')] # and choose your favourite LSM
246 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY', 'y')] # and choose your favourite LSM
247 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_YAMA', 'y')]
248 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_LANDLOCK', 'y')]
249 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DISABLE', 'is not set')]
250 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_BOOTPARAM', 'is not set')]
251 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DEVELOP', 'is not set')]
252 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_LOCKDOWN_LSM', 'y')]
253 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_LOCKDOWN_LSM_EARLY', 'y')]
254 l += [KconfigCheck('security_policy', 'kspp', 'LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY', 'y')]
255 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_WRITABLE_HOOKS', 'is not set')] # refers to SECURITY_SELINUX_DISABLE
257 # 'cut_attack_surface', 'defconfig'
258 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'SECCOMP', 'y')]
259 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'SECCOMP_FILTER', 'y')]
260 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'BPF_UNPRIV_DEFAULT_OFF', 'y'),
261 bpf_syscall_not_set)] # see unprivileged_bpf_disabled
262 if arch in ('X86_64', 'ARM64', 'X86_32'):
263 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'STRICT_DEVMEM', 'y'),
264 devmem_not_set)] # refers to LOCKDOWN
265 if arch in ('X86_64', 'X86_32'):
266 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'X86_INTEL_TSX_MODE_OFF', 'y')] # tsx=off
268 # 'cut_attack_surface', 'kspp'
269 l += [KconfigCheck('cut_attack_surface', 'kspp', 'SECURITY_DMESG_RESTRICT', 'y')]
270 l += [KconfigCheck('cut_attack_surface', 'kspp', 'ACPI_CUSTOM_METHOD', 'is not set')] # refers to LOCKDOWN
271 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_BRK', 'is not set')]
272 l += [KconfigCheck('cut_attack_surface', 'kspp', 'DEVKMEM', 'is not set')] # refers to LOCKDOWN
273 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set')]
274 l += [KconfigCheck('cut_attack_surface', 'kspp', 'BINFMT_MISC', 'is not set')]
275 l += [KconfigCheck('cut_attack_surface', 'kspp', 'INET_DIAG', 'is not set')]
276 l += [KconfigCheck('cut_attack_surface', 'kspp', 'KEXEC', 'is not set')] # refers to LOCKDOWN
277 l += [KconfigCheck('cut_attack_surface', 'kspp', 'PROC_KCORE', 'is not set')] # refers to LOCKDOWN
278 l += [KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_PTYS', 'is not set')]
279 l += [KconfigCheck('cut_attack_surface', 'kspp', 'HIBERNATION', 'is not set')] # refers to LOCKDOWN
280 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT', 'is not set')]
281 l += [KconfigCheck('cut_attack_surface', 'kspp', 'IA32_EMULATION', 'is not set')]
282 l += [KconfigCheck('cut_attack_surface', 'kspp', 'X86_X32', 'is not set')]
283 l += [KconfigCheck('cut_attack_surface', 'kspp', 'X86_X32_ABI', 'is not set')]
284 l += [KconfigCheck('cut_attack_surface', 'kspp', 'MODIFY_LDT_SYSCALL', 'is not set')]
285 l += [KconfigCheck('cut_attack_surface', 'kspp', 'OABI_COMPAT', 'is not set')]
286 l += [KconfigCheck('cut_attack_surface', 'kspp', 'X86_MSR', 'is not set')] # refers to LOCKDOWN
287 l += [modules_not_set]
288 l += [devmem_not_set]
289 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'IO_STRICT_DEVMEM', 'y'),
290 devmem_not_set)] # refers to LOCKDOWN
291 l += [AND(KconfigCheck('cut_attack_surface', 'kspp', 'LDISC_AUTOLOAD', 'is not set'),
292 KconfigCheck('cut_attack_surface', 'kspp', 'LDISC_AUTOLOAD', 'is present'))]
294 l += [KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_VSYSCALL_NONE', 'y')] # 'vsyscall=none'
296 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'STRICT_DEVMEM', 'y'),
297 devmem_not_set)] # refers to LOCKDOWN
299 # 'cut_attack_surface', 'grsec'
300 l += [KconfigCheck('cut_attack_surface', 'grsec', 'ZSMALLOC_STAT', 'is not set')]
301 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PAGE_OWNER', 'is not set')]
302 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_KMEMLEAK', 'is not set')]
303 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BINFMT_AOUT', 'is not set')]
304 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KPROBE_EVENTS', 'is not set')]
305 l += [KconfigCheck('cut_attack_surface', 'grsec', 'UPROBE_EVENTS', 'is not set')]
306 l += [KconfigCheck('cut_attack_surface', 'grsec', 'GENERIC_TRACER', 'is not set')] # refers to LOCKDOWN
307 l += [KconfigCheck('cut_attack_surface', 'grsec', 'FUNCTION_TRACER', 'is not set')]
308 l += [KconfigCheck('cut_attack_surface', 'grsec', 'STACK_TRACER', 'is not set')]
309 l += [KconfigCheck('cut_attack_surface', 'grsec', 'HIST_TRIGGERS', 'is not set')]
310 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BLK_DEV_IO_TRACE', 'is not set')]
311 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROC_VMCORE', 'is not set')]
312 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROC_PAGE_MONITOR', 'is not set')]
313 l += [KconfigCheck('cut_attack_surface', 'grsec', 'USELIB', 'is not set')]
314 l += [KconfigCheck('cut_attack_surface', 'grsec', 'CHECKPOINT_RESTORE', 'is not set')]
315 l += [KconfigCheck('cut_attack_surface', 'grsec', 'USERFAULTFD', 'is not set')]
316 l += [KconfigCheck('cut_attack_surface', 'grsec', 'HWPOISON_INJECT', 'is not set')]
317 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MEM_SOFT_DIRTY', 'is not set')]
318 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEVPORT', 'is not set')] # refers to LOCKDOWN
319 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_FS', 'is not set')] # refers to LOCKDOWN
320 l += [KconfigCheck('cut_attack_surface', 'grsec', 'NOTIFIER_ERROR_INJECTION', 'is not set')]
321 l += [KconfigCheck('cut_attack_surface', 'grsec', 'FAIL_FUTEX', 'is not set')]
322 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PUNIT_ATOM_DEBUG', 'is not set')]
323 l += [KconfigCheck('cut_attack_surface', 'grsec', 'ACPI_CONFIGFS', 'is not set')]
324 l += [KconfigCheck('cut_attack_surface', 'grsec', 'EDAC_DEBUG', 'is not set')]
325 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DRM_I915_DEBUG', 'is not set')]
326 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BCACHE_CLOSURES_DEBUG', 'is not set')]
327 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DVB_C8SECTPFE', 'is not set')]
328 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MTD_SLRAM', 'is not set')]
329 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MTD_PHRAM', 'is not set')]
330 l += [KconfigCheck('cut_attack_surface', 'grsec', 'IO_URING', 'is not set')]
331 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KCMP', 'is not set')]
332 l += [KconfigCheck('cut_attack_surface', 'grsec', 'RSEQ', 'is not set')]
333 l += [KconfigCheck('cut_attack_surface', 'grsec', 'LATENCYTOP', 'is not set')]
334 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KCOV', 'is not set')]
335 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROVIDE_OHCI1394_DMA_INIT', 'is not set')]
336 l += [KconfigCheck('cut_attack_surface', 'grsec', 'SUNRPC_DEBUG', 'is not set')]
337 l += [AND(KconfigCheck('cut_attack_surface', 'grsec', 'PTDUMP_DEBUGFS', 'is not set'),
338 KconfigCheck('cut_attack_surface', 'grsec', 'X86_PTDUMP', 'is not set'))]
340 # 'cut_attack_surface', 'maintainer'
341 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'DRM_LEGACY', 'is not set')] # recommended by Daniel Vetter in /issues/38
342 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'FB', 'is not set')] # recommended by Daniel Vetter in /issues/38
343 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'VT', 'is not set')] # recommended by Daniel Vetter in /issues/38
344 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD', 'is not set')] # recommended by Denis Efremov in /pull/54
345 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD_RAWCMD', 'is not set')] # recommended by Denis Efremov in /pull/62
346 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'NOUVEAU_LEGACY_CTX_SUPPORT', 'is not set')]
347 # recommended by Dave Airlie in kernel commit b30a43ac7132cdda
349 # 'cut_attack_surface', 'clipos'
350 l += [KconfigCheck('cut_attack_surface', 'clipos', 'STAGING', 'is not set')]
351 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KSM', 'is not set')] # to prevent FLUSH+RELOAD attack
352 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KALLSYMS', 'is not set')]
353 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_VSYSCALL_EMULATION', 'is not set')]
354 l += [KconfigCheck('cut_attack_surface', 'clipos', 'MAGIC_SYSRQ', 'is not set')]
355 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KEXEC_FILE', 'is not set')] # refers to LOCKDOWN (permissive)
356 l += [KconfigCheck('cut_attack_surface', 'clipos', 'USER_NS', 'is not set')] # user.max_user_namespaces=0
357 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_CPUID', 'is not set')]
358 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_IOPL_IOPERM', 'is not set')] # refers to LOCKDOWN
359 l += [KconfigCheck('cut_attack_surface', 'clipos', 'ACPI_TABLE_UPGRADE', 'is not set')] # refers to LOCKDOWN
360 l += [KconfigCheck('cut_attack_surface', 'clipos', 'EFI_CUSTOM_SSDT_OVERLAYS', 'is not set')]
361 l += [KconfigCheck('cut_attack_surface', 'clipos', 'COREDUMP', 'is not set')] # cut userspace attack surface
362 # l += [KconfigCheck('cut_attack_surface', 'clipos', 'IKCONFIG', 'is not set')] # no, IKCONFIG is needed for this check :)
364 # 'cut_attack_surface', 'lockdown'
365 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'EFI_TEST', 'is not set')] # refers to LOCKDOWN
366 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'MMIOTRACE_TEST', 'is not set')] # refers to LOCKDOWN
367 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'KPROBES', 'is not set')] # refers to LOCKDOWN
368 l += [bpf_syscall_not_set] # refers to LOCKDOWN
370 # 'cut_attack_surface', 'my'
371 l += [KconfigCheck('cut_attack_surface', 'my', 'MMIOTRACE', 'is not set')] # refers to LOCKDOWN (permissive)
372 l += [KconfigCheck('cut_attack_surface', 'my', 'LIVEPATCH', 'is not set')]
373 l += [KconfigCheck('cut_attack_surface', 'my', 'IP_DCCP', 'is not set')]
374 l += [KconfigCheck('cut_attack_surface', 'my', 'IP_SCTP', 'is not set')]
375 l += [KconfigCheck('cut_attack_surface', 'my', 'FTRACE', 'is not set')] # refers to LOCKDOWN
376 l += [KconfigCheck('cut_attack_surface', 'my', 'VIDEO_VIVID', 'is not set')]
377 l += [KconfigCheck('cut_attack_surface', 'my', 'INPUT_EVBUG', 'is not set')] # Can be used as a keylogger
378 l += [KconfigCheck('cut_attack_surface', 'my', 'KGDB', 'is not set')]
379 l += [KconfigCheck('cut_attack_surface', 'my', 'AIO', 'is not set')]
380 l += [OR(KconfigCheck('cut_attack_surface', 'my', 'TRIM_UNUSED_KSYMS', 'y'),
384 if arch in ('X86_64', 'ARM64', 'X86_32'):
385 l += [KconfigCheck('harden_userspace', 'defconfig', 'INTEGRITY', 'y')]
387 l += [KconfigCheck('harden_userspace', 'my', 'INTEGRITY', 'y')]
389 l += [KconfigCheck('harden_userspace', 'defconfig', 'ARM64_PTR_AUTH', 'y')]
390 l += [KconfigCheck('harden_userspace', 'defconfig', 'ARM64_BTI', 'y')]
391 if arch in ('ARM', 'X86_32'):
392 l += [KconfigCheck('harden_userspace', 'defconfig', 'VMSPLIT_3G', 'y')]
393 if arch in ('X86_64', 'ARM64'):
394 l += [KconfigCheck('harden_userspace', 'clipos', 'ARCH_MMAP_RND_BITS', '32')]
395 if arch in ('X86_32', 'ARM'):
396 l += [KconfigCheck('harden_userspace', 'my', 'ARCH_MMAP_RND_BITS', '16')]
399 def add_cmdline_checks(l, arch):
400 # Calling the CmdlineCheck class constructor:
401 # CmdlineCheck(reason, decision, name, expected)
403 # [!] Don't add CmdlineChecks in add_kconfig_checks() to avoid wrong results
404 # when the tool doesn't check the cmdline.
406 # [!] Make sure that values of the options in CmdlineChecks need normalization.
407 # For more info see normalize_cmdline_options().
409 # A common pattern for checking the 'param_x' cmdline parameter
410 # that __overrides__ the 'PARAM_X_DEFAULT' kconfig option:
411 # l += [OR(CmdlineCheck(reason, decision, 'param_x', '1'),
412 # AND(KconfigCheck(reason, decision, 'PARAM_X_DEFAULT_ON', 'y'),
413 # CmdlineCheck(reason, decision, 'param_x, 'is not set')))]
415 # Here we don't check the kconfig options or minimal kernel version
416 # required for the cmdline parameters. That would make the checks
417 # very complex and not give a 100% guarantee anyway.
419 # 'self_protection', 'defconfig'
420 l += [CmdlineCheck('self_protection', 'defconfig', 'nosmep', 'is not set')]
421 l += [CmdlineCheck('self_protection', 'defconfig', 'nosmap', 'is not set')]
422 l += [CmdlineCheck('self_protection', 'defconfig', 'nokaslr', 'is not set')]
423 l += [CmdlineCheck('self_protection', 'defconfig', 'nopti', 'is not set')]
424 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_v1', 'is not set')]
425 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_v2', 'is not set')]
426 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_bhb', 'is not set')]
427 l += [CmdlineCheck('self_protection', 'defconfig', 'nospec_store_bypass_disable', 'is not set')]
428 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nobti', 'is not set')]
429 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nopauth', 'is not set')]
430 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nomte', 'is not set')]
431 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_v2', 'is not off'),
432 CmdlineCheck('self_protection', 'defconfig', 'spectre_v2', 'is not set'))]
433 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_v2_user', 'is not off'),
434 CmdlineCheck('self_protection', 'defconfig', 'spectre_v2_user', 'is not set'))]
435 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spec_store_bypass_disable', 'is not off'),
436 CmdlineCheck('self_protection', 'defconfig', 'spec_store_bypass_disable', 'is not set'))]
437 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'l1tf', 'is not off'),
438 CmdlineCheck('self_protection', 'defconfig', 'l1tf', 'is not set'))]
439 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'mds', 'is not off'),
440 CmdlineCheck('self_protection', 'defconfig', 'mds', 'is not set'))]
441 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'tsx_async_abort', 'is not off'),
442 CmdlineCheck('self_protection', 'defconfig', 'tsx_async_abort', 'is not set'))]
443 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'srbds', 'is not off'),
444 CmdlineCheck('self_protection', 'defconfig', 'srbds', 'is not set'))]
445 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'mmio_stale_data', 'is not off'),
446 CmdlineCheck('self_protection', 'defconfig', 'mmio_stale_data', 'is not set'))]
447 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not off'),
448 CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not set'))]
449 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not off'),
450 CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not set'))]
451 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'kvm.nx_huge_pages', 'is not off'),
452 CmdlineCheck('self_protection', 'defconfig', 'kvm.nx_huge_pages', 'is not set'))]
454 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'kernel'),
455 CmdlineCheck('self_protection', 'my', 'ssbd', 'force-on'),
456 CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'is not set'))]
457 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'rodata', 'full'),
458 AND(KconfigCheck('self_protection', 'defconfig', 'RODATA_FULL_DEFAULT_ENABLED', 'y'),
459 CmdlineCheck('self_protection', 'defconfig', 'rodata', 'is not set')))]
461 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'rodata', '1'),
462 CmdlineCheck('self_protection', 'defconfig', 'rodata', 'is not set'))]
464 # 'self_protection', 'kspp'
465 l += [CmdlineCheck('self_protection', 'kspp', 'nosmt', 'is present')]
466 l += [CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt')] # 'nosmt' by kspp + 'auto' by defconfig
467 l += [OR(CmdlineCheck('self_protection', 'kspp', 'init_on_alloc', '1'),
468 AND(KconfigCheck('self_protection', 'kspp', 'INIT_ON_ALLOC_DEFAULT_ON', 'y'),
469 CmdlineCheck('self_protection', 'kspp', 'init_on_alloc', 'is not set')))]
470 l += [OR(CmdlineCheck('self_protection', 'kspp', 'init_on_free', '1'),
471 AND(KconfigCheck('self_protection', 'kspp', 'INIT_ON_FREE_DEFAULT_ON', 'y'),
472 CmdlineCheck('self_protection', 'kspp', 'init_on_free', 'is not set')),
473 AND(CmdlineCheck('self_protection', 'kspp', 'page_poison', '1'),
474 KconfigCheck('self_protection', 'kspp', 'PAGE_POISONING_ZERO', 'y'),
475 CmdlineCheck('self_protection', 'kspp', 'slub_debug', 'P')))]
476 l += [OR(CmdlineCheck('self_protection', 'kspp', 'slab_nomerge', 'is present'),
477 AND(KconfigCheck('self_protection', 'clipos', 'SLAB_MERGE_DEFAULT', 'is not set'),
478 CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set'),
479 CmdlineCheck('self_protection', 'clipos', 'slub_merge', 'is not set')))]
480 l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.strict', '1'),
481 AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y'),
482 CmdlineCheck('self_protection', 'kspp', 'iommu.strict', 'is not set')))]
483 l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.passthrough', '0'),
484 AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set'),
485 CmdlineCheck('self_protection', 'kspp', 'iommu.passthrough', 'is not set')))]
486 # The cmdline checks compatible with the kconfig recommendations of the KSPP project...
487 l += [OR(CmdlineCheck('self_protection', 'kspp', 'hardened_usercopy', '1'),
488 AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY', 'y'),
489 CmdlineCheck('self_protection', 'kspp', 'hardened_usercopy', 'is not set')))]
490 l += [OR(CmdlineCheck('self_protection', 'kspp', 'slab_common.usercopy_fallback', '0'),
491 AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_FALLBACK', 'is not set'),
492 CmdlineCheck('self_protection', 'kspp', 'slab_common.usercopy_fallback', 'is not set')))]
494 if arch in ('X86_64', 'ARM64', 'X86_32'):
495 l += [OR(CmdlineCheck('self_protection', 'kspp', 'randomize_kstack_offset', '1'),
496 AND(KconfigCheck('self_protection', 'kspp', 'RANDOMIZE_KSTACK_OFFSET_DEFAULT', 'y'),
497 CmdlineCheck('self_protection', 'kspp', 'randomize_kstack_offset', 'is not set')))]
498 if arch in ('X86_64', 'X86_32'):
499 l += [AND(CmdlineCheck('self_protection', 'kspp', 'pti', 'on'),
500 CmdlineCheck('self_protection', 'defconfig', 'nopti', 'is not set'))]
502 # 'self_protection', 'clipos'
503 l += [CmdlineCheck('self_protection', 'clipos', 'page_alloc.shuffle', '1')]
504 if arch in ('X86_64', 'X86_32'):
505 l += [CmdlineCheck('self_protection', 'clipos', 'iommu', 'force')]
507 # 'cut_attack_surface', 'defconfig'
508 if arch in ('X86_64', 'X86_32'):
509 l += [OR(CmdlineCheck('cut_attack_surface', 'defconfig', 'tsx', 'off'),
510 AND(KconfigCheck('cut_attack_surface', 'defconfig', 'X86_INTEL_TSX_MODE_OFF', 'y'),
511 CmdlineCheck('cut_attack_surface', 'defconfig', 'tsx', 'is not set')))]
513 # 'cut_attack_surface', 'kspp'
515 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vsyscall', 'none'),
516 AND(KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_VSYSCALL_NONE', 'y'),
517 CmdlineCheck('cut_attack_surface', 'kspp', 'vsyscall', 'is not set')))]
519 # 'cut_attack_surface', 'grsec'
520 # The cmdline checks compatible with the kconfig options disabled by grsecurity...
521 l += [OR(CmdlineCheck('cut_attack_surface', 'grsec', 'debugfs', 'off'),
522 KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_FS', 'is not set'))] # ... the end
524 # 'cut_attack_surface', 'my'
525 l += [CmdlineCheck('cut_attack_surface', 'my', 'sysrq_always_enabled', 'is not set')]
528 def normalize_cmdline_options(option, value):
529 # Don't normalize the cmdline option values if
530 # the Linux kernel doesn't use kstrtobool() for them
531 if option == 'debugfs':
532 # See debugfs_kernel() in fs/debugfs/inode.c
534 if option == 'mitigations':
535 # See mitigations_parse_cmdline() in kernel/cpu.c
538 # See pti_check_boottime_disable() in arch/x86/mm/pti.c
540 if option == 'spectre_v2':
541 # See spectre_v2_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
543 if option == 'spectre_v2_user':
544 # See spectre_v2_parse_user_cmdline() in arch/x86/kernel/cpu/bugs.c
546 if option == 'spec_store_bypass_disable':
547 # See ssb_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
550 # See l1tf_cmdline() in arch/x86/kernel/cpu/bugs.c
553 # See mds_cmdline() in arch/x86/kernel/cpu/bugs.c
555 if option == 'tsx_async_abort':
556 # See tsx_async_abort_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
558 if option == 'srbds':
559 # See srbds_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
561 if option == 'mmio_stale_data':
562 # See mmio_stale_data_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
564 if option == 'retbleed':
565 # See retbleed_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
568 # See tsx_init() in arch/x86/kernel/cpu/tsx.c
571 # Implement a limited part of the kstrtobool() logic
572 if value in ('1', 'on', 'On', 'ON', 'y', 'Y', 'yes', 'Yes', 'YES'):
574 if value in ('0', 'off', 'Off', 'OFF', 'n', 'N', 'no', 'No', 'NO'):
577 # Preserve unique values