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
12 # pylint: disable=too-many-branches,too-many-statements,too-many-locals
14 from typing import List
15 from .engine import StrOrNone, ChecklistObjType, KconfigCheck, CmdlineCheck, SysctlCheck, VersionCheck, OR, AND
18 def add_kconfig_checks(l: List[ChecklistObjType], arch: str) -> None:
19 assert(arch), 'empty arch'
21 # Calling the KconfigCheck class constructor:
22 # KconfigCheck(reason, decision, name, expected)
24 # [!] Don't add CmdlineChecks in add_kconfig_checks() to avoid wrong results
25 # when the tool doesn't check the cmdline.
27 efi_not_set = KconfigCheck('-', '-', 'EFI', 'is not set')
28 cc_is_gcc = KconfigCheck('-', '-', 'CC_IS_GCC', 'y') # exists since v4.18
29 cc_is_clang = KconfigCheck('-', '-', 'CC_IS_CLANG', 'y') # exists since v4.18
30 if arch in ('X86_64', 'X86_32'):
31 cpu_sup_amd_not_set = KconfigCheck('-', '-', 'CPU_SUP_AMD', 'is not set')
32 cpu_sup_intel_not_set = KconfigCheck('-', '-', 'CPU_SUP_INTEL', 'is not set')
34 modules_not_set = KconfigCheck('cut_attack_surface', 'kspp', 'MODULES', 'is not set') # radical, but may be useful in some cases
35 devmem_not_set = KconfigCheck('cut_attack_surface', 'kspp', 'DEVMEM', 'is not set') # refers to LOCKDOWN
36 bpf_syscall_not_set = KconfigCheck('cut_attack_surface', 'lockdown', 'BPF_SYSCALL', 'is not set') # refers to LOCKDOWN
38 # 'self_protection', 'defconfig'
39 l += [KconfigCheck('self_protection', 'defconfig', 'BUG', 'y')]
40 l += [KconfigCheck('self_protection', 'defconfig', 'SLUB_DEBUG', 'y')]
41 l += [KconfigCheck('self_protection', 'defconfig', 'THREAD_INFO_IN_TASK', 'y')]
42 iommu_support_is_set = KconfigCheck('self_protection', 'defconfig', 'IOMMU_SUPPORT', 'y')
43 l += [iommu_support_is_set] # is needed for mitigating DMA attacks
44 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR', 'y'),
45 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR', 'y'),
46 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_REGULAR', 'y'),
47 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_AUTO', 'y'),
48 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_STRONG', 'y'))]
49 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR_STRONG', 'y'),
50 KconfigCheck('self_protection', 'defconfig', 'CC_STACKPROTECTOR_STRONG', 'y'))]
51 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STRICT_KERNEL_RWX', 'y'),
52 KconfigCheck('self_protection', 'defconfig', 'DEBUG_RODATA', 'y'))] # before v4.11
53 l += [OR(KconfigCheck('self_protection', 'defconfig', 'STRICT_MODULE_RWX', 'y'),
54 KconfigCheck('self_protection', 'defconfig', 'DEBUG_SET_MODULE_RONX', 'y'),
55 modules_not_set)] # DEBUG_SET_MODULE_RONX was before v4.11
56 l += [OR(KconfigCheck('self_protection', 'defconfig', 'REFCOUNT_FULL', 'y'),
57 VersionCheck((5, 4, 208)))]
58 # REFCOUNT_FULL is enabled by default since v5.5,
59 # and this is backported to v5.4.208
60 l += [OR(KconfigCheck('self_protection', 'defconfig', 'INIT_STACK_ALL_ZERO', 'y'),
61 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STRUCTLEAK_BYREF_ALL', 'y'))]
62 if arch in ('X86_64', 'ARM64', 'X86_32'):
63 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_BASE', 'y')]
64 vmap_stack_is_set = KconfigCheck('self_protection', 'defconfig', 'VMAP_STACK', 'y')
65 if arch in ('X86_64', 'ARM64', 'ARM'):
66 l += [vmap_stack_is_set]
67 if arch in ('X86_64', 'X86_32'):
68 l += [KconfigCheck('self_protection', 'defconfig', 'DEBUG_WX', 'y')]
69 l += [KconfigCheck('self_protection', 'defconfig', 'WERROR', 'y')]
70 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE', 'y')]
71 l += [KconfigCheck('self_protection', 'defconfig', 'SYN_COOKIES', 'y')] # another reason?
72 microcode_is_set = KconfigCheck('self_protection', 'defconfig', 'MICROCODE', 'y')
73 l += [microcode_is_set] # is needed for mitigating CPU bugs
74 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MICROCODE_INTEL', 'y'),
75 cpu_sup_intel_not_set,
77 VersionCheck((6, 6, 0))))] # MICROCODE_INTEL was included in MICROCODE since v6.6
78 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MICROCODE_AMD', 'y'),
81 VersionCheck((6, 6, 0))))] # MICROCODE_AMD was included in MICROCODE since v6.6
82 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_SMAP', 'y'),
83 VersionCheck((5, 19, 0)))] # X86_SMAP is enabled by default since v5.19
84 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_UMIP', 'y'),
85 KconfigCheck('self_protection', 'defconfig', 'X86_INTEL_UMIP', 'y'))]
86 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_MCE_INTEL', 'y'),
87 cpu_sup_intel_not_set)]
88 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_MCE_AMD', 'y'),
90 l += [OR(KconfigCheck('self_protection', 'defconfig', 'CPU_MITIGATIONS', 'y'),
91 KconfigCheck('self_protection', 'defconfig', 'SPECULATION_MITIGATIONS', 'y'))]
92 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_RETPOLINE', 'y'),
93 KconfigCheck('self_protection', 'defconfig', 'RETPOLINE', 'y'))]
94 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_RFDS', 'y'),
95 cpu_sup_intel_not_set)]
96 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_SPECTRE_BHI', 'y'),
97 cpu_sup_intel_not_set)]
98 if arch in ('ARM64', 'ARM'):
99 l += [KconfigCheck('self_protection', 'defconfig', 'HW_RANDOM_TPM', 'y')]
100 l += [KconfigCheck('self_protection', 'defconfig', 'IOMMU_DEFAULT_DMA_STRICT', 'y')]
101 l += [KconfigCheck('self_protection', 'defconfig', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set')] # true if IOMMU_DEFAULT_DMA_STRICT is set
102 l += [KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR_PER_TASK', 'y')]
104 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_MEMORY', 'y')]
105 l += [KconfigCheck('self_protection', 'defconfig', 'X86_KERNEL_IBT', 'y')]
106 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_PAGE_TABLE_ISOLATION', 'y'),
107 KconfigCheck('self_protection', 'defconfig', 'PAGE_TABLE_ISOLATION', 'y'))]
108 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_SRSO', 'y'),
109 KconfigCheck('self_protection', 'defconfig', 'CPU_SRSO', 'y'),
110 cpu_sup_amd_not_set)]
111 l += [AND(KconfigCheck('self_protection', 'defconfig', 'INTEL_IOMMU', 'y'),
112 iommu_support_is_set)]
113 l += [AND(KconfigCheck('self_protection', 'defconfig', 'AMD_IOMMU', 'y'),
114 iommu_support_is_set)]
116 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_PAN', 'y')]
117 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_EPAN', 'y')]
118 l += [KconfigCheck('self_protection', 'defconfig', 'UNMAP_KERNEL_AT_EL0', 'y')]
119 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_E0PD', 'y')]
120 l += [KconfigCheck('self_protection', 'defconfig', 'RODATA_FULL_DEFAULT_ENABLED', 'y')]
121 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_PTR_AUTH_KERNEL', 'y')]
122 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_BTI_KERNEL', 'y')]
123 l += [KconfigCheck('self_protection', 'defconfig', 'MITIGATE_SPECTRE_BRANCH_HISTORY', 'y')]
124 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_MTE', 'y')]
125 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_MODULE_REGION_FULL', 'y')]
126 l += [OR(KconfigCheck('self_protection', 'defconfig', 'HARDEN_EL2_VECTORS', 'y'),
127 AND(KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_BASE', 'y'),
128 VersionCheck((5, 9, 0))))] # HARDEN_EL2_VECTORS was included in RANDOMIZE_BASE in v5.9
129 l += [OR(KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_PREDICTOR', 'y'),
130 VersionCheck((5, 10, 0)))] # HARDEN_BRANCH_PREDICTOR is enabled by default since v5.10
132 l += [KconfigCheck('self_protection', 'defconfig', 'CPU_SW_DOMAIN_PAN', 'y')]
133 l += [KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_PREDICTOR', 'y')]
134 l += [KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_HISTORY', 'y')]
135 l += [KconfigCheck('self_protection', 'defconfig', 'DEBUG_ALIGN_RODATA', 'y')]
137 # 'self_protection', 'kspp'
138 l += [KconfigCheck('self_protection', 'kspp', 'LIST_HARDENED', 'y')]
139 l += [KconfigCheck('self_protection', 'kspp', 'RANDOM_KMALLOC_CACHES', 'y')]
140 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_MERGE_DEFAULT', 'is not set')]
141 l += [KconfigCheck('self_protection', 'kspp', 'PAGE_TABLE_CHECK', 'y')]
142 l += [KconfigCheck('self_protection', 'kspp', 'PAGE_TABLE_CHECK_ENFORCED', 'y')]
143 l += [KconfigCheck('self_protection', 'kspp', 'BUG_ON_DATA_CORRUPTION', 'y')]
144 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_FREELIST_HARDENED', 'y')]
145 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_FREELIST_RANDOM', 'y')]
146 l += [KconfigCheck('self_protection', 'kspp', 'SHUFFLE_PAGE_ALLOCATOR', 'y')]
147 l += [KconfigCheck('self_protection', 'kspp', 'FORTIFY_SOURCE', 'y')]
148 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_LIST', 'y')]
149 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_VIRTUAL', 'y')]
150 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_SG', 'y')]
151 l += [KconfigCheck('self_protection', 'kspp', 'INIT_ON_ALLOC_DEFAULT_ON', 'y')]
152 l += [KconfigCheck('self_protection', 'kspp', 'STATIC_USERMODEHELPER', 'y')] # needs userspace support
153 l += [KconfigCheck('self_protection', 'kspp', 'SCHED_CORE', 'y')]
154 l += [KconfigCheck('self_protection', 'kspp', 'SECURITY_LOCKDOWN_LSM', 'y')]
155 l += [KconfigCheck('self_protection', 'kspp', 'SECURITY_LOCKDOWN_LSM_EARLY', 'y')]
156 l += [KconfigCheck('self_protection', 'kspp', 'LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY', 'y')]
157 cfi_clang_is_set = KconfigCheck('self_protection', 'kspp', 'CFI_CLANG', 'y')
158 cfi_clang_permissive_not_set = KconfigCheck('self_protection', 'kspp', 'CFI_PERMISSIVE', 'is not set')
159 l += [OR(KconfigCheck('self_protection', 'kspp', 'DEBUG_CREDENTIALS', 'y'),
160 VersionCheck((6, 6, 8)))] # DEBUG_CREDENTIALS was dropped in v6.6.8
161 l += [OR(KconfigCheck('self_protection', 'kspp', 'DEBUG_NOTIFIERS', 'y'),
162 AND(cfi_clang_is_set,
163 cfi_clang_permissive_not_set,
165 l += [OR(KconfigCheck('self_protection', 'kspp', 'SCHED_STACK_END_CHECK', 'y'),
167 kfence_is_set = KconfigCheck('self_protection', 'kspp', 'KFENCE', 'y')
169 l += [AND(KconfigCheck('self_protection', 'kspp', 'KFENCE_SAMPLE_INTERVAL', 'is not off'),
171 randstruct_is_set = OR(KconfigCheck('self_protection', 'kspp', 'RANDSTRUCT_FULL', 'y'),
172 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_RANDSTRUCT', 'y'))
173 l += [randstruct_is_set]
174 # l += [AND(KconfigCheck('self_protection', 'kspp', 'RANDSTRUCT_PERFORMANCE', 'is not set'),
175 # KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_RANDSTRUCT_PERFORMANCE', 'is not set'),
176 # randstruct_is_set)] # Comment this out for now: KSPP has revoked this recommendation
177 hardened_usercopy_is_set = KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY', 'y')
178 l += [hardened_usercopy_is_set]
179 l += [AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_FALLBACK', 'is not set'),
180 hardened_usercopy_is_set)] # usercopy whitelist violations should be prohibited
181 l += [AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_PAGESPAN', 'is not set'),
182 hardened_usercopy_is_set)] # this debugging for HARDENED_USERCOPY is not needed for security
183 l += [AND(KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_LATENT_ENTROPY', 'y'),
185 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG', 'y'),
187 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_ALL', 'y'),
189 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_SHA512', 'y'),
190 KconfigCheck('self_protection', 'a13xp0p0v', 'MODULE_SIG_SHA3_512', 'y'),
192 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_FORCE', 'y'),
193 modules_not_set)] # refers to LOCKDOWN
194 l += [OR(KconfigCheck('self_protection', 'kspp', 'INIT_ON_FREE_DEFAULT_ON', 'y'),
195 KconfigCheck('self_protection', 'kspp', 'PAGE_POISONING_ZERO', 'y'))]
196 # CONFIG_INIT_ON_FREE_DEFAULT_ON was added in v5.3.
197 # CONFIG_PAGE_POISONING_ZERO was removed in v5.11.
198 # Starting from v5.11 CONFIG_PAGE_POISONING unconditionally checks
199 # the 0xAA poison pattern on allocation.
200 # That brings higher performance penalty.
201 l += [OR(KconfigCheck('self_protection', 'kspp', 'EFI_DISABLE_PCI_DMA', 'y'),
203 l += [OR(KconfigCheck('self_protection', 'kspp', 'RESET_ATTACK_MITIGATION', 'y'),
204 efi_not_set)] # needs userspace support (systemd)
205 ubsan_bounds_is_set = KconfigCheck('self_protection', 'kspp', 'UBSAN_BOUNDS', 'y')
206 l += [ubsan_bounds_is_set]
207 l += [OR(KconfigCheck('self_protection', 'kspp', 'UBSAN_LOCAL_BOUNDS', 'y'),
208 AND(ubsan_bounds_is_set,
210 l += [AND(KconfigCheck('self_protection', 'kspp', 'UBSAN_TRAP', 'y'),
212 KconfigCheck('self_protection', 'kspp', 'UBSAN_SHIFT', 'is not set'),
213 KconfigCheck('self_protection', 'kspp', 'UBSAN_DIV_ZERO', 'is not set'),
214 KconfigCheck('self_protection', 'kspp', 'UBSAN_UNREACHABLE', 'is not set'),
215 KconfigCheck('self_protection', 'kspp', 'UBSAN_BOOL', 'is not set'),
216 KconfigCheck('self_protection', 'kspp', 'UBSAN_ENUM', 'is not set'),
217 KconfigCheck('self_protection', 'kspp', 'UBSAN_ALIGNMENT', 'is not set'))] # only array index bounds checking with traps
218 l += [AND(KconfigCheck('self_protection', 'kspp', 'UBSAN_SANITIZE_ALL', 'y'),
219 ubsan_bounds_is_set)]
220 if arch in ('X86_64', 'ARM64', 'X86_32'):
221 stackleak_is_set = KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STACKLEAK', 'y')
222 l += [AND(stackleak_is_set,
224 l += [AND(KconfigCheck('self_protection', 'kspp', 'STACKLEAK_METRICS', 'is not set'),
227 l += [AND(KconfigCheck('self_protection', 'kspp', 'STACKLEAK_RUNTIME_DISABLE', 'is not set'),
230 l += [KconfigCheck('self_protection', 'kspp', 'RANDOMIZE_KSTACK_OFFSET_DEFAULT', 'y')]
231 if arch in ('X86_64', 'ARM64'):
232 l += [AND(cfi_clang_is_set,
234 l += [AND(cfi_clang_permissive_not_set,
237 if arch in ('X86_64', 'X86_32'):
238 l += [KconfigCheck('self_protection', 'kspp', 'HW_RANDOM_TPM', 'y')]
239 l += [KconfigCheck('self_protection', 'kspp', 'DEFAULT_MMAP_MIN_ADDR', '65536')]
240 l += [KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y')]
241 l += [KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set')] # true if IOMMU_DEFAULT_DMA_STRICT is set
242 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU_DEFAULT_ON', 'y'),
243 iommu_support_is_set)]
244 if arch in ('ARM64', 'ARM'):
245 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_WX', 'y')]
246 l += [KconfigCheck('self_protection', 'kspp', 'WERROR', 'y')]
247 l += [KconfigCheck('self_protection', 'kspp', 'DEFAULT_MMAP_MIN_ADDR', '32768')]
248 l += [KconfigCheck('self_protection', 'kspp', 'SYN_COOKIES', 'y')] # another reason?
250 l += [OR(KconfigCheck('self_protection', 'kspp', 'MITIGATION_SLS', 'y'),
251 KconfigCheck('self_protection', 'kspp', 'SLS', 'y'))] # vs CVE-2021-26341 in Straight-Line-Speculation
252 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU_SVM', 'y'),
253 iommu_support_is_set)]
254 l += [AND(KconfigCheck('self_protection', 'kspp', 'AMD_IOMMU_V2', 'y'),
255 iommu_support_is_set)]
257 l += [KconfigCheck('self_protection', 'kspp', 'ARM64_SW_TTBR0_PAN', 'y')]
258 l += [KconfigCheck('self_protection', 'kspp', 'SHADOW_CALL_STACK', 'y')]
259 l += [KconfigCheck('self_protection', 'kspp', 'UNWIND_PATCH_PAC_INTO_SCS', 'y')]
260 l += [KconfigCheck('self_protection', 'kspp', 'KASAN_HW_TAGS', 'y')] # see also: kasan=on, kasan.stacktrace=off, kasan.fault=panic
262 l += [KconfigCheck('self_protection', 'kspp', 'HIGHMEM64G', 'y')]
263 l += [KconfigCheck('self_protection', 'kspp', 'X86_PAE', 'y')]
264 l += [OR(KconfigCheck('self_protection', 'kspp', 'MITIGATION_PAGE_TABLE_ISOLATION', 'y'),
265 KconfigCheck('self_protection', 'kspp', 'PAGE_TABLE_ISOLATION', 'y'))]
266 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU', 'y'),
267 iommu_support_is_set)]
270 if arch in ('X86_64', 'ARM64', 'X86_32'):
271 l += [KconfigCheck('security_policy', 'defconfig', 'SECURITY', 'y')]
273 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY', 'y')]
274 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_YAMA', 'y')]
275 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_LANDLOCK', 'y')]
276 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DISABLE', 'is not set')]
277 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_BOOTPARAM', 'is not set')]
278 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DEVELOP', 'is not set')]
279 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_WRITABLE_HOOKS', 'is not set')] # refers to SECURITY_SELINUX_DISABLE
280 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DEBUG', 'is not set')]
281 l += [OR(KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_SELINUX', 'y'),
282 KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_APPARMOR', 'y'),
283 KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_SMACK', 'y'),
284 KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_TOMOYO', 'y'))] # one of major LSMs implementing MAC
286 # N.B. We don't use 'if arch' for the 'cut_attack_surface' checks that require 'is not set'.
287 # It makes the maintainance easier. These kernel options should be disabled anyway.
288 # 'cut_attack_surface', 'defconfig'
289 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'SECCOMP', 'y')]
290 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'SECCOMP_FILTER', 'y')]
291 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'BPF_UNPRIV_DEFAULT_OFF', 'y'),
292 bpf_syscall_not_set)] # see unprivileged_bpf_disabled
293 if arch in ('X86_64', 'ARM64', 'X86_32'):
294 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'STRICT_DEVMEM', 'y'),
295 devmem_not_set)] # refers to LOCKDOWN
296 if arch in ('X86_64', 'X86_32'):
297 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'X86_INTEL_TSX_MODE_OFF', 'y'),
298 cpu_sup_intel_not_set)] # tsx=off
300 # 'cut_attack_surface', 'kspp'
301 l += [KconfigCheck('cut_attack_surface', 'kspp', 'SECURITY_DMESG_RESTRICT', 'y')]
302 l += [KconfigCheck('cut_attack_surface', 'kspp', 'ACPI_CUSTOM_METHOD', 'is not set')] # refers to LOCKDOWN
303 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_BRK', 'is not set')]
304 l += [KconfigCheck('cut_attack_surface', 'kspp', 'DEVKMEM', 'is not set')] # refers to LOCKDOWN
305 l += [KconfigCheck('cut_attack_surface', 'kspp', 'BINFMT_MISC', 'is not set')]
306 l += [KconfigCheck('cut_attack_surface', 'kspp', 'INET_DIAG', 'is not set')]
307 l += [KconfigCheck('cut_attack_surface', 'kspp', 'KEXEC', 'is not set')] # refers to LOCKDOWN
308 l += [KconfigCheck('cut_attack_surface', 'kspp', 'PROC_KCORE', 'is not set')] # refers to LOCKDOWN
309 l += [KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_PTYS', 'is not set')]
310 l += [KconfigCheck('cut_attack_surface', 'kspp', 'HIBERNATION', 'is not set')] # refers to LOCKDOWN
311 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT', 'is not set')]
312 l += [KconfigCheck('cut_attack_surface', 'kspp', 'IA32_EMULATION', 'is not set')]
313 l += [KconfigCheck('cut_attack_surface', 'kspp', 'X86_X32', 'is not set')]
314 l += [KconfigCheck('cut_attack_surface', 'kspp', 'X86_X32_ABI', 'is not set')]
315 l += [KconfigCheck('cut_attack_surface', 'kspp', 'MODIFY_LDT_SYSCALL', 'is not set')]
316 l += [KconfigCheck('cut_attack_surface', 'kspp', 'OABI_COMPAT', 'is not set')]
317 l += [KconfigCheck('cut_attack_surface', 'kspp', 'X86_MSR', 'is not set')] # refers to LOCKDOWN
318 l += [KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_TIOCSTI', 'is not set')]
319 l += [KconfigCheck('cut_attack_surface', 'kspp', 'MODULE_FORCE_LOAD', 'is not set')]
320 l += [modules_not_set]
321 l += [devmem_not_set]
322 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'IO_STRICT_DEVMEM', 'y'),
323 devmem_not_set)] # refers to LOCKDOWN
324 l += [AND(KconfigCheck('cut_attack_surface', 'kspp', 'LDISC_AUTOLOAD', 'is not set'),
325 KconfigCheck('cut_attack_surface', 'kspp', 'LDISC_AUTOLOAD', 'is present'))]
326 if arch in ('X86_64', 'X86_32'):
327 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set')]
328 # CONFIG_COMPAT_VDSO disabled ASLR of vDSO only on X86_64 and X86_32;
329 # on ARM64 this option has different meaning
331 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'X86_VSYSCALL_EMULATION', 'is not set'),
332 KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_VSYSCALL_NONE', 'y'))]
333 # disabling X86_VSYSCALL_EMULATION turns vsyscall off completely,
334 # and LEGACY_VSYSCALL_NONE can be changed at boot time via the cmdline parameter
336 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'STRICT_DEVMEM', 'y'),
337 devmem_not_set)] # refers to LOCKDOWN
339 # 'cut_attack_surface', 'grsec'
340 l += [KconfigCheck('cut_attack_surface', 'grsec', 'ZSMALLOC_STAT', 'is not set')]
341 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PAGE_OWNER', 'is not set')]
342 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_KMEMLEAK', 'is not set')]
343 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BINFMT_AOUT', 'is not set')]
344 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KPROBE_EVENTS', 'is not set')]
345 l += [KconfigCheck('cut_attack_surface', 'grsec', 'UPROBE_EVENTS', 'is not set')]
346 l += [KconfigCheck('cut_attack_surface', 'grsec', 'GENERIC_TRACER', 'is not set')] # refers to LOCKDOWN
347 l += [KconfigCheck('cut_attack_surface', 'grsec', 'FUNCTION_TRACER', 'is not set')]
348 l += [KconfigCheck('cut_attack_surface', 'grsec', 'STACK_TRACER', 'is not set')]
349 l += [KconfigCheck('cut_attack_surface', 'grsec', 'HIST_TRIGGERS', 'is not set')]
350 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BLK_DEV_IO_TRACE', 'is not set')]
351 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROC_VMCORE', 'is not set')]
352 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROC_PAGE_MONITOR', 'is not set')]
353 l += [KconfigCheck('cut_attack_surface', 'grsec', 'USELIB', 'is not set')]
354 l += [KconfigCheck('cut_attack_surface', 'grsec', 'CHECKPOINT_RESTORE', 'is not set')]
355 l += [KconfigCheck('cut_attack_surface', 'grsec', 'USERFAULTFD', 'is not set')]
356 l += [KconfigCheck('cut_attack_surface', 'grsec', 'HWPOISON_INJECT', 'is not set')]
357 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MEM_SOFT_DIRTY', 'is not set')]
358 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEVPORT', 'is not set')] # refers to LOCKDOWN
359 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_FS', 'is not set')] # refers to LOCKDOWN
360 l += [KconfigCheck('cut_attack_surface', 'grsec', 'NOTIFIER_ERROR_INJECTION', 'is not set')]
361 l += [KconfigCheck('cut_attack_surface', 'grsec', 'FAIL_FUTEX', 'is not set')]
362 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PUNIT_ATOM_DEBUG', 'is not set')]
363 l += [KconfigCheck('cut_attack_surface', 'grsec', 'ACPI_CONFIGFS', 'is not set')]
364 l += [KconfigCheck('cut_attack_surface', 'grsec', 'EDAC_DEBUG', 'is not set')]
365 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DRM_I915_DEBUG', 'is not set')]
366 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BCACHE_CLOSURES_DEBUG', 'is not set')]
367 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DVB_C8SECTPFE', 'is not set')]
368 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MTD_SLRAM', 'is not set')]
369 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MTD_PHRAM', 'is not set')]
370 l += [KconfigCheck('cut_attack_surface', 'grsec', 'IO_URING', 'is not set')]
371 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KCMP', 'is not set')]
372 l += [KconfigCheck('cut_attack_surface', 'grsec', 'RSEQ', 'is not set')]
373 l += [KconfigCheck('cut_attack_surface', 'grsec', 'LATENCYTOP', 'is not set')]
374 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KCOV', 'is not set')]
375 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROVIDE_OHCI1394_DMA_INIT', 'is not set')]
376 l += [KconfigCheck('cut_attack_surface', 'grsec', 'SUNRPC_DEBUG', 'is not set')]
377 l += [AND(KconfigCheck('cut_attack_surface', 'grsec', 'PTDUMP_DEBUGFS', 'is not set'),
378 KconfigCheck('cut_attack_surface', 'grsec', 'X86_PTDUMP', 'is not set'))]
380 # 'cut_attack_surface', 'maintainer'
381 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'DRM_LEGACY', 'is not set')] # recommended by Daniel Vetter in /issues/38
382 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'FB', 'is not set')] # recommended by Daniel Vetter in /issues/38
383 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'VT', 'is not set')] # recommended by Daniel Vetter in /issues/38
384 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD', 'is not set')] # recommended by Denis Efremov in /pull/54
385 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD_RAWCMD', 'is not set')] # recommended by Denis Efremov in /pull/62
386 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'NOUVEAU_LEGACY_CTX_SUPPORT', 'is not set')]
387 # recommended by Dave Airlie in kernel commit b30a43ac7132cdda
389 # 'cut_attack_surface', 'clipos'
390 l += [KconfigCheck('cut_attack_surface', 'clipos', 'STAGING', 'is not set')]
391 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KSM', 'is not set')] # to prevent FLUSH+RELOAD attack
392 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KALLSYMS', 'is not set')]
393 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KEXEC_FILE', 'is not set')] # refers to LOCKDOWN (permissive)
394 l += [KconfigCheck('cut_attack_surface', 'clipos', 'USER_NS', 'is not set')] # user.max_user_namespaces=0
395 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_CPUID', 'is not set')]
396 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_IOPL_IOPERM', 'is not set')] # refers to LOCKDOWN
397 l += [KconfigCheck('cut_attack_surface', 'clipos', 'ACPI_TABLE_UPGRADE', 'is not set')] # refers to LOCKDOWN
398 l += [KconfigCheck('cut_attack_surface', 'clipos', 'EFI_CUSTOM_SSDT_OVERLAYS', 'is not set')]
399 l += [KconfigCheck('cut_attack_surface', 'clipos', 'AIO', 'is not set')]
400 # l += [KconfigCheck('cut_attack_surface', 'clipos', 'IKCONFIG', 'is not set')] # no, IKCONFIG is needed for this check :)
401 l += [OR(KconfigCheck('cut_attack_surface', 'clipos', 'MAGIC_SYSRQ', 'is not set'),
402 KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'MAGIC_SYSRQ_DEFAULT_ENABLE', '0x0'))]
404 # 'cut_attack_surface', 'lockdown'
405 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'EFI_TEST', 'is not set')] # refers to LOCKDOWN
406 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'MMIOTRACE_TEST', 'is not set')] # refers to LOCKDOWN
407 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'KPROBES', 'is not set')] # refers to LOCKDOWN
408 l += [bpf_syscall_not_set] # refers to LOCKDOWN
410 # 'cut_attack_surface', 'a13xp0p0v'
411 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'MMIOTRACE', 'is not set')] # refers to LOCKDOWN (permissive)
412 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'LIVEPATCH', 'is not set')]
413 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'IP_DCCP', 'is not set')]
414 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'IP_SCTP', 'is not set')]
415 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'FTRACE', 'is not set')] # refers to LOCKDOWN
416 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'VIDEO_VIVID', 'is not set')]
417 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'INPUT_EVBUG', 'is not set')] # Can be used as a keylogger
418 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'KGDB', 'is not set')]
419 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'CORESIGHT', 'is not set')]
420 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'XFS_SUPPORT_V4', 'is not set')]
421 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'BLK_DEV_WRITE_MOUNTED', 'is not set')]
422 l += [OR(KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'TRIM_UNUSED_KSYMS', 'y'),
424 l += [OR(KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'MAGIC_SYSRQ_SERIAL', 'is not set'),
425 KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'MAGIC_SYSRQ_DEFAULT_ENABLE', '0x0'))]
429 l += [KconfigCheck('harden_userspace', 'defconfig', 'ARM64_PTR_AUTH', 'y')]
430 l += [KconfigCheck('harden_userspace', 'defconfig', 'ARM64_BTI', 'y')]
431 if arch in ('ARM', 'X86_32'):
432 l += [KconfigCheck('harden_userspace', 'defconfig', 'VMSPLIT_3G', 'y')]
433 l += [KconfigCheck('harden_userspace', 'clipos', 'COREDUMP', 'is not set')]
434 l += [KconfigCheck('harden_userspace', 'a13xp0p0v', 'ARCH_MMAP_RND_BITS', 'MAX')] # 'MAX' value is refined using ARCH_MMAP_RND_BITS_MAX
436 l += [KconfigCheck('harden_userspace', 'kspp', 'X86_USER_SHADOW_STACK', 'y')]
439 def add_cmdline_checks(l: List[ChecklistObjType], arch: str) -> None:
440 assert(arch), 'empty arch'
442 # Calling the CmdlineCheck class constructor:
443 # CmdlineCheck(reason, decision, name, expected)
445 # [!] Don't add CmdlineChecks in add_kconfig_checks() to avoid wrong results
446 # when the tool doesn't check the cmdline.
448 # [!] Make sure that values of the options in CmdlineChecks need normalization.
449 # For more info see normalize_cmdline_options().
451 # A common pattern for checking the 'param_x' cmdline parameter
452 # that __overrides__ the 'PARAM_X_DEFAULT' kconfig option:
453 # l += [OR(CmdlineCheck(reason, decision, 'param_x', '1'),
454 # AND(KconfigCheck(reason, decision, 'PARAM_X_DEFAULT_ON', 'y'),
455 # CmdlineCheck(reason, decision, 'param_x, 'is not set')))]
457 # Here we don't check the kconfig options or minimal kernel version
458 # required for the cmdline parameters. That would make the checks
459 # very complex and not give a 100% guarantee anyway.
461 # 'self_protection', 'defconfig'
462 l += [CmdlineCheck('self_protection', 'defconfig', 'nosmep', 'is not set')]
463 l += [CmdlineCheck('self_protection', 'defconfig', 'nosmap', 'is not set')]
464 l += [CmdlineCheck('self_protection', 'defconfig', 'nokaslr', 'is not set')]
465 l += [CmdlineCheck('self_protection', 'defconfig', 'nopti', 'is not set')]
466 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_v1', 'is not set')]
467 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_v2', 'is not set')]
468 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_bhb', 'is not set')]
469 l += [CmdlineCheck('self_protection', 'defconfig', 'nospec_store_bypass_disable', 'is not set')]
470 l += [CmdlineCheck('self_protection', 'defconfig', 'dis_ucode_ldr', 'is not set')]
471 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nobti', 'is not set')]
472 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nopauth', 'is not set')]
473 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nomte', 'is not set')]
474 if arch in ('X86_64', 'X86_32'):
475 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_v2', 'is not off'),
476 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
477 CmdlineCheck('self_protection', 'defconfig', 'spectre_v2', 'is not set')))]
478 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_v2_user', 'is not off'),
479 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
480 CmdlineCheck('self_protection', 'defconfig', 'spectre_v2_user', 'is not set')))]
481 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_bhi', 'is not off'),
482 AND(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_SPECTRE_BHI', 'y'),
483 CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
484 CmdlineCheck('self_protection', 'defconfig', 'spectre_bhi', 'is not set')))]
485 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spec_store_bypass_disable', 'is not off'),
486 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
487 CmdlineCheck('self_protection', 'defconfig', 'spec_store_bypass_disable', 'is not set')))]
488 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'l1tf', 'is not off'),
489 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
490 CmdlineCheck('self_protection', 'defconfig', 'l1tf', 'is not set')))]
491 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'mds', 'is not off'),
492 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
493 CmdlineCheck('self_protection', 'defconfig', 'mds', 'is not set')))]
494 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'tsx_async_abort', 'is not off'),
495 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
496 CmdlineCheck('self_protection', 'defconfig', 'tsx_async_abort', 'is not set')))]
497 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'srbds', 'is not off'),
498 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
499 CmdlineCheck('self_protection', 'defconfig', 'srbds', 'is not set')))]
500 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'mmio_stale_data', 'is not off'),
501 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
502 CmdlineCheck('self_protection', 'defconfig', 'mmio_stale_data', 'is not set')))]
503 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not off'),
504 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
505 CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not set')))]
506 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spec_rstack_overflow', 'is not off'),
507 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
508 CmdlineCheck('self_protection', 'defconfig', 'spec_rstack_overflow', 'is not set')))]
509 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'gather_data_sampling', 'is not off'),
510 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
511 CmdlineCheck('self_protection', 'defconfig', 'gather_data_sampling', 'is not set')))]
512 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'reg_file_data_sampling', 'is not off'),
513 AND(KconfigCheck('self_protection', 'defconfig', 'MITIGATION_RFDS', 'y'),
514 CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
515 CmdlineCheck('self_protection', 'defconfig', 'reg_file_data_sampling', 'is not set')))]
517 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not off'),
518 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
519 CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not set')))]
520 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'kernel'),
521 CmdlineCheck('self_protection', 'a13xp0p0v', 'ssbd', 'force-on'),
522 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
523 CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'is not set')))]
524 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'rodata', 'full'),
525 AND(KconfigCheck('self_protection', 'defconfig', 'RODATA_FULL_DEFAULT_ENABLED', 'y'),
526 CmdlineCheck('self_protection', 'defconfig', 'rodata', 'is not set')))]
528 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'rodata', 'on'),
529 CmdlineCheck('self_protection', 'defconfig', 'rodata', 'is not set'))]
531 # 'self_protection', 'kspp'
532 l += [CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt')]
533 l += [CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set')] # consequence of 'slab_nomerge' by kspp
534 l += [CmdlineCheck('self_protection', 'kspp', 'slub_merge', 'is not set')] # consequence of 'slab_nomerge' by kspp
535 l += [CmdlineCheck('self_protection', 'kspp', 'page_alloc.shuffle', '1')]
536 l += [CmdlineCheck('self_protection', 'kspp', 'cfi', 'kcfi')]
537 l += [OR(CmdlineCheck('self_protection', 'kspp', 'slab_nomerge', 'is present'),
538 AND(KconfigCheck('self_protection', 'clipos', 'SLAB_MERGE_DEFAULT', 'is not set'),
539 CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set'),
540 CmdlineCheck('self_protection', 'kspp', 'slub_merge', 'is not set')))]
541 l += [OR(CmdlineCheck('self_protection', 'kspp', 'init_on_alloc', '1'),
542 AND(KconfigCheck('self_protection', 'kspp', 'INIT_ON_ALLOC_DEFAULT_ON', 'y'),
543 CmdlineCheck('self_protection', 'kspp', 'init_on_alloc', 'is not set')))]
544 l += [OR(CmdlineCheck('self_protection', 'kspp', 'init_on_free', '1'),
545 AND(KconfigCheck('self_protection', 'kspp', 'INIT_ON_FREE_DEFAULT_ON', 'y'),
546 CmdlineCheck('self_protection', 'kspp', 'init_on_free', 'is not set')),
547 AND(CmdlineCheck('self_protection', 'kspp', 'page_poison', '1'),
548 KconfigCheck('self_protection', 'kspp', 'PAGE_POISONING_ZERO', 'y'),
549 CmdlineCheck('self_protection', 'kspp', 'slub_debug', 'P')))]
550 l += [OR(CmdlineCheck('self_protection', 'kspp', 'hardened_usercopy', '1'),
551 AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY', 'y'),
552 CmdlineCheck('self_protection', 'kspp', 'hardened_usercopy', 'is not set')))]
553 l += [AND(CmdlineCheck('self_protection', 'kspp', 'slab_common.usercopy_fallback', 'is not set'),
554 KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_FALLBACK', 'is not set'))]
555 # Consequence of the HARDENED_USERCOPY_FALLBACK check by kspp.
556 # Don't require slab_common.usercopy_fallback=0,
557 # since HARDENED_USERCOPY_FALLBACK was removed in Linux v5.16.
558 if arch in ('X86_64', 'ARM64', 'X86_32'):
559 l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.strict', '1'),
560 AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y'),
561 CmdlineCheck('self_protection', 'kspp', 'iommu.strict', 'is not set')))]
562 l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.passthrough', '0'),
563 AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set'),
564 CmdlineCheck('self_protection', 'kspp', 'iommu.passthrough', 'is not set')))]
565 l += [OR(CmdlineCheck('self_protection', 'kspp', 'randomize_kstack_offset', '1'),
566 AND(KconfigCheck('self_protection', 'kspp', 'RANDOMIZE_KSTACK_OFFSET_DEFAULT', 'y'),
567 CmdlineCheck('self_protection', 'kspp', 'randomize_kstack_offset', 'is not set')))]
568 if arch in ('X86_64', 'X86_32'):
569 l += [AND(CmdlineCheck('self_protection', 'kspp', 'pti', 'on'),
570 CmdlineCheck('self_protection', 'defconfig', 'nopti', 'is not set'))]
572 # 'self_protection', 'clipos'
573 if arch in ('X86_64', 'X86_32'):
574 l += [CmdlineCheck('self_protection', 'clipos', 'iommu', 'force')]
576 # 'self_protection', 'a13xp0p0v'
577 l += [OR(CmdlineCheck('self_protection', 'a13xp0p0v', 'kfence.sample_interval', 'is not off'),
578 AND(KconfigCheck('self_protection', 'a13xp0p0v', 'KFENCE_SAMPLE_INTERVAL', 'is not off'),
579 CmdlineCheck('self_protection', 'a13xp0p0v', 'kfence.sample_interval', 'is not set')))]
581 # 'cut_attack_surface', 'defconfig'
582 if arch in ('X86_64', 'X86_32'):
583 tsx_not_set = CmdlineCheck('cut_attack_surface', 'defconfig', 'tsx', 'is not set')
584 l += [OR(CmdlineCheck('cut_attack_surface', 'defconfig', 'tsx', 'off'),
585 AND(KconfigCheck('cut_attack_surface', 'defconfig', 'X86_INTEL_TSX_MODE_OFF', 'y'),
587 AND(KconfigCheck('-', '-', 'CPU_SUP_INTEL', 'is not set'),
590 # 'cut_attack_surface', 'kspp'
591 l += [CmdlineCheck('cut_attack_surface', 'kspp', 'nosmt', 'is present')] # slow (high performance penalty)
593 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vsyscall', 'none'),
594 KconfigCheck('cut_attack_surface', 'kspp', 'X86_VSYSCALL_EMULATION', 'is not set'),
595 AND(KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_VSYSCALL_NONE', 'y'),
596 CmdlineCheck('cut_attack_surface', 'kspp', 'vsyscall', 'is not set')))]
597 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vdso32', '0'),
598 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', '1'),
599 AND(KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set'),
600 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', 'is not set')))] # the vdso32 parameter must not be 2
602 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vdso32', '0'),
603 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso', '0'),
604 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', '1'),
605 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso', '1'),
606 AND(KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set'),
607 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', 'is not set'),
608 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso', 'is not set')))] # the vdso and vdso32 parameters must not be 2
610 # 'cut_attack_surface', 'grsec'
611 # The cmdline checks compatible with the kconfig options disabled by grsecurity...
612 l += [OR(CmdlineCheck('cut_attack_surface', 'grsec', 'debugfs', 'off'),
613 KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_FS', 'is not set'))] # ... the end
615 # 'cut_attack_surface', 'a13xp0p0v'
616 l += [CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'sysrq_always_enabled', 'is not set')]
617 l += [OR(CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'bdev_allow_write_mounted', '0'),
618 AND(KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'BLK_DEV_WRITE_MOUNTED', 'is not set'),
619 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'bdev_allow_write_mounted', 'is not set')))]
621 l += [OR(CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'ia32_emulation', '0'),
622 KconfigCheck('cut_attack_surface', 'kspp', 'IA32_EMULATION', 'is not set'),
623 AND(KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'IA32_EMULATION_DEFAULT_DISABLED', 'y'),
624 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'ia32_emulation', 'is not set')))]
627 l += [CmdlineCheck('harden_userspace', 'defconfig', 'norandmaps', 'is not set')]
630 no_kstrtobool_options = [
631 'debugfs', # See debugfs_kernel() in fs/debugfs/inode.c
632 'mitigations', # See mitigations_parse_cmdline() in kernel/cpu.c
633 'pti', # See pti_check_boottime_disable() in arch/x86/mm/pti.c
634 'spectre_v2', # See spectre_v2_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
635 'spectre_v2_user', # See spectre_v2_parse_user_cmdline() in arch/x86/kernel/cpu/bugs.c
636 'spectre_bhi', # See spectre_bhi_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
637 'spec_store_bypass_disable', # See ssb_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
638 'l1tf', # See l1tf_cmdline() in arch/x86/kernel/cpu/bugs.c
639 'mds', # See mds_cmdline() in arch/x86/kernel/cpu/bugs.c
640 'tsx_async_abort', # See tsx_async_abort_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
641 'srbds', # See srbds_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
642 'mmio_stale_data', # See mmio_stale_data_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
643 'retbleed', # See retbleed_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
644 'rodata', # See set_debug_rodata() in init/main.c
645 'ssbd', # See parse_spectre_v4_param() in arch/arm64/kernel/proton-pack.c
646 'spec_rstack_overflow', # See srso_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
647 'gather_data_sampling', # See gds_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
648 'reg_file_data_sampling', # See rfds_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
649 'slub_debug', # See setup_slub_debug() in mm/slub.c
650 'iommu', # See iommu_setup() in arch/x86/kernel/pci-dma.c
651 'vsyscall', # See vsyscall_setup() in arch/x86/entry/vsyscall/vsyscall_64.c
652 'vdso32', # See vdso32_setup() in arch/x86/entry/vdso/vdso32-setup.c
653 'vdso', # See vdso32_setup() in arch/x86/entry/vdso/vdso32-setup.c
654 'tsx' # See tsx_init() in arch/x86/kernel/cpu/tsx.c
658 def normalize_cmdline_options(option: str, value: str) -> str:
659 # Don't normalize the cmdline option values if
660 # the Linux kernel doesn't use kstrtobool() for them
661 if option in no_kstrtobool_options:
664 # Implement a limited part of the kstrtobool() logic
665 if value.lower() in ('1', 'on', 'y', 'yes', 't', 'true'):
667 if value.lower() in ('0', 'off', 'n', 'no', 'f', 'false'):
670 # Preserve unique values
674 # Ideas of security hardening sysctls:
675 # what about bpf_jit_enable?
676 # vm.mmap_min_addr has a good value
677 # nosmt sysfs control file
678 # vm.mmap_rnd_bits=max (?)
679 # abi.vsyscall32 (any value except 2)
680 # net.ipv4.tcp_syncookies=1 (?)
682 def add_sysctl_checks(l: List[ChecklistObjType], _arch: StrOrNone) -> None:
683 # This function may be called with arch=None
685 # Calling the SysctlCheck class constructor:
686 # SysctlCheck(reason, decision, name, expected)
688 # Use an omnipresent kconfig symbol to see if we have a kconfig file for checking
689 have_kconfig = KconfigCheck('-', '-', 'LOCALVERSION', 'is present')
691 l += [OR(SysctlCheck('self_protection', 'kspp', 'net.core.bpf_jit_harden', '2'),
692 AND(KconfigCheck('-', '-', 'BPF_JIT', 'is not set'),
694 # Choosing a right value for 'kernel.oops_limit' and 'kernel.warn_limit' is not easy.
695 # A small value (e.g. 1, which is recommended by KSPP) allows easy DoS.
696 # A large value (e.g. 10000, which is default 'kernel.oops_limit') may miss the exploit attempt.
697 # Let's choose 100 as a reasonable compromise.
698 l += [SysctlCheck('self_protection', 'a13xp0p0v', 'kernel.oops_limit', '100')]
699 l += [SysctlCheck('self_protection', 'a13xp0p0v', 'kernel.warn_limit', '100')]
701 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.dmesg_restrict', '1')]
702 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.perf_event_paranoid', '3')] # with a custom patch, see https://lwn.net/Articles/696216/
703 l += [SysctlCheck('cut_attack_surface', 'kspp', 'user.max_user_namespaces', '0')] # may break the upower daemon in Ubuntu
704 l += [SysctlCheck('cut_attack_surface', 'kspp', 'dev.tty.ldisc_autoload', '0')]
705 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.kptr_restrict', '2')]
706 l += [SysctlCheck('cut_attack_surface', 'kspp', 'dev.tty.legacy_tiocsti', '0')]
707 l += [OR(SysctlCheck('cut_attack_surface', 'kspp', 'kernel.kexec_load_disabled', '1'),
708 AND(KconfigCheck('-', '-', 'KEXEC_CORE', 'is not set'),
710 l += [OR(SysctlCheck('cut_attack_surface', 'kspp', 'kernel.unprivileged_bpf_disabled', '1'),
711 AND(KconfigCheck('cut_attack_surface', 'lockdown', 'BPF_SYSCALL', 'is not set'),
713 l += [OR(SysctlCheck('cut_attack_surface', 'kspp', 'vm.unprivileged_userfaultfd', '0'),
714 AND(KconfigCheck('cut_attack_surface', 'grsec', 'USERFAULTFD', 'is not set'),
716 # At first, it disabled unprivileged userfaultfd,
717 # and since v5.11 it enables unprivileged userfaultfd for user-mode only.
719 l += [OR(SysctlCheck('cut_attack_surface', 'kspp', 'kernel.modules_disabled', '1'),
720 AND(KconfigCheck('cut_attack_surface', 'kspp', 'MODULES', 'is not set'),
721 have_kconfig))] # radical, but may be useful in some cases
723 l += [OR(SysctlCheck('cut_attack_surface', 'a13xp0p0v', 'kernel.sysrq', '0'),
724 AND(KconfigCheck('cut_attack_surface', 'clipos', 'MAGIC_SYSRQ', 'is not set'),
727 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_symlinks', '1')]
728 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_hardlinks', '1')]
729 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_fifos', '2')]
730 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_regular', '2')]
731 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.suid_dumpable', '0')]
732 l += [SysctlCheck('harden_userspace', 'kspp', 'kernel.randomize_va_space', '2')]
733 l += [SysctlCheck('harden_userspace', 'kspp', 'kernel.yama.ptrace_scope', '3')]