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