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