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