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,too-many-locals
14 from .engine import KconfigCheck, CmdlineCheck, SysctlCheck, VersionCheck, OR, AND
17 def add_kconfig_checks(l, arch):
18 assert(arch), 'empty arch'
20 # Calling the KconfigCheck class constructor:
21 # KconfigCheck(reason, decision, name, expected)
23 # [!] Don't add CmdlineChecks in add_kconfig_checks() to avoid wrong results
24 # when the tool doesn't check the cmdline.
26 efi_not_set = KconfigCheck('-', '-', 'EFI', 'is not set')
27 cc_is_gcc = KconfigCheck('-', '-', 'CC_IS_GCC', 'y') # exists since v4.18
28 cc_is_clang = KconfigCheck('-', '-', 'CC_IS_CLANG', 'y') # exists since v4.18
30 modules_not_set = KconfigCheck('cut_attack_surface', 'kspp', 'MODULES', 'is not set') # radical, but may be useful in some cases
31 devmem_not_set = KconfigCheck('cut_attack_surface', 'kspp', 'DEVMEM', 'is not set') # refers to LOCKDOWN
32 bpf_syscall_not_set = KconfigCheck('cut_attack_surface', 'lockdown', 'BPF_SYSCALL', 'is not set') # refers to LOCKDOWN
34 # 'self_protection', 'defconfig'
35 l += [KconfigCheck('self_protection', 'defconfig', 'BUG', 'y')]
36 l += [KconfigCheck('self_protection', 'defconfig', 'SLUB_DEBUG', 'y')]
37 l += [KconfigCheck('self_protection', 'defconfig', 'THREAD_INFO_IN_TASK', 'y')]
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, 4, 208)))]
54 # REFCOUNT_FULL is enabled by default since v5.5,
55 # and this is backported to v5.4.208
56 l += [OR(KconfigCheck('self_protection', 'defconfig', 'INIT_STACK_ALL_ZERO', 'y'),
57 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STRUCTLEAK_BYREF_ALL', 'y'))]
58 if arch in ('X86_64', 'ARM64', 'X86_32'):
59 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_BASE', 'y')]
60 vmap_stack_is_set = KconfigCheck('self_protection', 'defconfig', 'VMAP_STACK', 'y')
61 if arch in ('X86_64', 'ARM64', 'ARM'):
62 l += [vmap_stack_is_set]
63 if arch in ('X86_64', 'X86_32'):
64 l += [KconfigCheck('self_protection', 'defconfig', 'SPECULATION_MITIGATIONS', 'y')]
65 l += [KconfigCheck('self_protection', 'defconfig', 'DEBUG_WX', 'y')]
66 l += [KconfigCheck('self_protection', 'defconfig', 'WERROR', 'y')]
67 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE', 'y')]
68 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE_INTEL', 'y')]
69 l += [KconfigCheck('self_protection', 'defconfig', 'X86_MCE_AMD', 'y')]
70 l += [KconfigCheck('self_protection', 'defconfig', 'RETPOLINE', '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'),
76 VersionCheck((6, 6, 0))))] # MICROCODE_INTEL was included in MICROCODE since v6.6
77 l += [OR(KconfigCheck('self_protection', 'defconfig', 'MICROCODE_AMD', 'y'),
79 VersionCheck((6, 6, 0))))] # MICROCODE_AMD was included in MICROCODE since v6.6
80 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_SMAP', 'y'),
81 VersionCheck((5, 19, 0)))] # X86_SMAP is enabled by default since v5.19
82 l += [OR(KconfigCheck('self_protection', 'defconfig', 'X86_UMIP', 'y'),
83 KconfigCheck('self_protection', 'defconfig', 'X86_INTEL_UMIP', 'y'))]
84 if arch in ('ARM64', 'ARM'):
85 l += [KconfigCheck('self_protection', 'defconfig', 'HW_RANDOM_TPM', 'y')]
86 l += [KconfigCheck('self_protection', 'defconfig', 'IOMMU_DEFAULT_DMA_STRICT', 'y')]
87 l += [KconfigCheck('self_protection', 'defconfig', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set')] # true if IOMMU_DEFAULT_DMA_STRICT is set
88 l += [KconfigCheck('self_protection', 'defconfig', 'STACKPROTECTOR_PER_TASK', 'y')]
90 l += [KconfigCheck('self_protection', 'defconfig', 'PAGE_TABLE_ISOLATION', 'y')]
91 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_MEMORY', 'y')]
92 l += [KconfigCheck('self_protection', 'defconfig', 'X86_KERNEL_IBT', 'y')]
93 l += [KconfigCheck('self_protection', 'defconfig', 'CPU_SRSO', 'y')]
94 l += [AND(KconfigCheck('self_protection', 'defconfig', 'INTEL_IOMMU', 'y'),
95 iommu_support_is_set)]
96 l += [AND(KconfigCheck('self_protection', 'defconfig', 'AMD_IOMMU', 'y'),
97 iommu_support_is_set)]
99 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_PAN', 'y')]
100 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_EPAN', 'y')]
101 l += [KconfigCheck('self_protection', 'defconfig', 'UNMAP_KERNEL_AT_EL0', 'y')]
102 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_E0PD', 'y')]
103 l += [KconfigCheck('self_protection', 'defconfig', 'RODATA_FULL_DEFAULT_ENABLED', 'y')]
104 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_PTR_AUTH_KERNEL', 'y')]
105 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_BTI_KERNEL', 'y')]
106 l += [KconfigCheck('self_protection', 'defconfig', 'MITIGATE_SPECTRE_BRANCH_HISTORY', 'y')]
107 l += [KconfigCheck('self_protection', 'defconfig', 'ARM64_MTE', 'y')]
108 l += [KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_MODULE_REGION_FULL', 'y')]
109 l += [OR(KconfigCheck('self_protection', 'defconfig', 'HARDEN_EL2_VECTORS', 'y'),
110 AND(KconfigCheck('self_protection', 'defconfig', 'RANDOMIZE_BASE', 'y'),
111 VersionCheck((5, 9, 0))))] # HARDEN_EL2_VECTORS was included in RANDOMIZE_BASE in v5.9
112 l += [OR(KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_PREDICTOR', 'y'),
113 VersionCheck((5, 10, 0)))] # HARDEN_BRANCH_PREDICTOR is enabled by default since v5.10
115 l += [KconfigCheck('self_protection', 'defconfig', 'CPU_SW_DOMAIN_PAN', 'y')]
116 l += [KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_PREDICTOR', 'y')]
117 l += [KconfigCheck('self_protection', 'defconfig', 'HARDEN_BRANCH_HISTORY', 'y')]
118 l += [KconfigCheck('self_protection', 'defconfig', 'DEBUG_ALIGN_RODATA', 'y')]
120 # 'self_protection', 'kspp'
121 l += [KconfigCheck('self_protection', 'kspp', 'BUG_ON_DATA_CORRUPTION', 'y')]
122 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_FREELIST_HARDENED', 'y')]
123 l += [KconfigCheck('self_protection', 'kspp', 'SLAB_FREELIST_RANDOM', 'y')]
124 l += [KconfigCheck('self_protection', 'kspp', 'SHUFFLE_PAGE_ALLOCATOR', 'y')]
125 l += [KconfigCheck('self_protection', 'kspp', 'FORTIFY_SOURCE', 'y')]
126 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_LIST', 'y')]
127 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_VIRTUAL', 'y')]
128 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_SG', 'y')]
129 l += [KconfigCheck('self_protection', 'kspp', 'INIT_ON_ALLOC_DEFAULT_ON', 'y')]
130 l += [KconfigCheck('self_protection', 'kspp', 'STATIC_USERMODEHELPER', 'y')] # needs userspace support
131 l += [KconfigCheck('self_protection', 'kspp', 'SCHED_CORE', 'y')]
132 l += [KconfigCheck('self_protection', 'kspp', 'SECURITY_LOCKDOWN_LSM', 'y')]
133 l += [KconfigCheck('self_protection', 'kspp', 'SECURITY_LOCKDOWN_LSM_EARLY', 'y')]
134 l += [KconfigCheck('self_protection', 'kspp', 'LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY', 'y')]
135 cfi_clang_is_set = KconfigCheck('self_protection', 'kspp', 'CFI_CLANG', 'y')
136 cfi_clang_permissive_not_set = KconfigCheck('self_protection', 'kspp', 'CFI_PERMISSIVE', 'is not set')
137 l += [OR(KconfigCheck('self_protection', 'kspp', 'DEBUG_CREDENTIALS', 'y'),
138 VersionCheck((6, 6, 8)))] # DEBUG_CREDENTIALS was dropped in v6.6.8
139 l += [OR(KconfigCheck('self_protection', 'kspp', 'DEBUG_NOTIFIERS', 'y'),
140 AND(cfi_clang_is_set,
141 cfi_clang_permissive_not_set,
143 l += [OR(KconfigCheck('self_protection', 'kspp', 'SCHED_STACK_END_CHECK', 'y'),
145 kfence_is_set = KconfigCheck('self_protection', 'kspp', 'KFENCE', 'y')
147 l += [AND(KconfigCheck('self_protection', 'a13xp0p0v', 'KFENCE_SAMPLE_INTERVAL', 'is not off'),
149 randstruct_is_set = OR(KconfigCheck('self_protection', 'kspp', 'RANDSTRUCT_FULL', 'y'),
150 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_RANDSTRUCT', 'y'))
151 l += [randstruct_is_set]
152 l += [AND(KconfigCheck('self_protection', 'kspp', 'RANDSTRUCT_PERFORMANCE', 'is not set'),
153 KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_RANDSTRUCT_PERFORMANCE', 'is not set'),
155 hardened_usercopy_is_set = KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY', 'y')
156 l += [hardened_usercopy_is_set]
157 l += [AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_FALLBACK', 'is not set'),
158 hardened_usercopy_is_set)] # usercopy whitelist violations should be prohibited
159 l += [AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_PAGESPAN', 'is not set'),
160 hardened_usercopy_is_set)] # this debugging for HARDENED_USERCOPY is not needed for security
161 l += [AND(KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_LATENT_ENTROPY', 'y'),
163 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG', 'y'),
165 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_ALL', 'y'),
167 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_SHA512', 'y'),
168 KconfigCheck('self_protection', 'a13xp0p0v', 'MODULE_SIG_SHA3_512', 'y'),
170 l += [OR(KconfigCheck('self_protection', 'kspp', 'MODULE_SIG_FORCE', 'y'),
171 modules_not_set)] # refers to LOCKDOWN
172 l += [OR(KconfigCheck('self_protection', 'kspp', 'INIT_ON_FREE_DEFAULT_ON', 'y'),
173 KconfigCheck('self_protection', 'kspp', 'PAGE_POISONING_ZERO', 'y'))]
174 # CONFIG_INIT_ON_FREE_DEFAULT_ON was added in v5.3.
175 # CONFIG_PAGE_POISONING_ZERO was removed in v5.11.
176 # Starting from v5.11 CONFIG_PAGE_POISONING unconditionally checks
177 # the 0xAA poison pattern on allocation.
178 # That brings higher performance penalty.
179 l += [OR(KconfigCheck('self_protection', 'kspp', 'EFI_DISABLE_PCI_DMA', 'y'),
181 l += [OR(KconfigCheck('self_protection', 'kspp', 'RESET_ATTACK_MITIGATION', 'y'),
182 efi_not_set)] # needs userspace support (systemd)
183 ubsan_bounds_is_set = KconfigCheck('self_protection', 'kspp', 'UBSAN_BOUNDS', 'y')
184 l += [ubsan_bounds_is_set]
185 l += [OR(KconfigCheck('self_protection', 'kspp', 'UBSAN_LOCAL_BOUNDS', 'y'),
186 AND(ubsan_bounds_is_set,
188 l += [AND(KconfigCheck('self_protection', 'kspp', 'UBSAN_TRAP', 'y'),
190 KconfigCheck('self_protection', 'kspp', 'UBSAN_SHIFT', 'is not set'),
191 KconfigCheck('self_protection', 'kspp', 'UBSAN_DIV_ZERO', 'is not set'),
192 KconfigCheck('self_protection', 'kspp', 'UBSAN_UNREACHABLE', 'is not set'),
193 KconfigCheck('self_protection', 'kspp', 'UBSAN_BOOL', 'is not set'),
194 KconfigCheck('self_protection', 'kspp', 'UBSAN_ENUM', 'is not set'),
195 KconfigCheck('self_protection', 'kspp', 'UBSAN_ALIGNMENT', 'is not set'))] # only array index bounds checking with traps
196 l += [AND(KconfigCheck('self_protection', 'kspp', 'UBSAN_SANITIZE_ALL', 'y'),
197 ubsan_bounds_is_set)]
198 if arch in ('X86_64', 'ARM64', 'X86_32'):
199 stackleak_is_set = KconfigCheck('self_protection', 'kspp', 'GCC_PLUGIN_STACKLEAK', 'y')
200 l += [AND(stackleak_is_set,
202 l += [AND(KconfigCheck('self_protection', 'kspp', 'STACKLEAK_METRICS', 'is not set'),
205 l += [AND(KconfigCheck('self_protection', 'kspp', 'STACKLEAK_RUNTIME_DISABLE', 'is not set'),
208 l += [KconfigCheck('self_protection', 'kspp', 'RANDOMIZE_KSTACK_OFFSET_DEFAULT', 'y')]
209 if arch in ('X86_64', 'ARM64'):
210 l += [AND(cfi_clang_is_set,
212 l += [AND(cfi_clang_permissive_not_set,
215 if arch in ('X86_64', 'X86_32'):
216 l += [KconfigCheck('self_protection', 'kspp', 'HW_RANDOM_TPM', 'y')]
217 l += [KconfigCheck('self_protection', 'kspp', 'DEFAULT_MMAP_MIN_ADDR', '65536')]
218 l += [KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y')]
219 l += [KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set')] # true if IOMMU_DEFAULT_DMA_STRICT is set
220 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU_DEFAULT_ON', 'y'),
221 iommu_support_is_set)]
222 if arch in ('ARM64', 'ARM'):
223 l += [KconfigCheck('self_protection', 'kspp', 'DEBUG_WX', 'y')]
224 l += [KconfigCheck('self_protection', 'kspp', 'WERROR', 'y')]
225 l += [KconfigCheck('self_protection', 'kspp', 'DEFAULT_MMAP_MIN_ADDR', '32768')]
226 l += [KconfigCheck('self_protection', 'kspp', 'SYN_COOKIES', 'y')] # another reason?
228 l += [KconfigCheck('self_protection', 'kspp', 'SLS', 'y')] # vs CVE-2021-26341 in Straight-Line-Speculation
229 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU_SVM', 'y'),
230 iommu_support_is_set)]
231 l += [AND(KconfigCheck('self_protection', 'kspp', 'AMD_IOMMU_V2', 'y'),
232 iommu_support_is_set)]
234 l += [KconfigCheck('self_protection', 'kspp', 'ARM64_SW_TTBR0_PAN', 'y')]
235 l += [KconfigCheck('self_protection', 'kspp', 'SHADOW_CALL_STACK', 'y')]
236 l += [KconfigCheck('self_protection', 'kspp', 'KASAN_HW_TAGS', 'y')] # see also: kasan=on, kasan.stacktrace=off, kasan.fault=panic
238 l += [KconfigCheck('self_protection', 'kspp', 'PAGE_TABLE_ISOLATION', 'y')]
239 l += [KconfigCheck('self_protection', 'kspp', 'HIGHMEM64G', 'y')]
240 l += [KconfigCheck('self_protection', 'kspp', 'X86_PAE', 'y')]
241 l += [AND(KconfigCheck('self_protection', 'kspp', 'INTEL_IOMMU', 'y'),
242 iommu_support_is_set)]
244 # 'self_protection', 'clipos'
245 l += [KconfigCheck('self_protection', 'clipos', 'SLAB_MERGE_DEFAULT', 'is not set')]
247 # 'self_protection', 'a13xp0p0v'
248 l += [KconfigCheck('self_protection', 'a13xp0p0v', 'LIST_HARDENED', 'y')]
249 l += [KconfigCheck('self_protection', 'a13xp0p0v', 'RANDOM_KMALLOC_CACHES', 'y')]
252 if arch in ('X86_64', 'ARM64', 'X86_32'):
253 l += [KconfigCheck('security_policy', 'defconfig', 'SECURITY', 'y')]
255 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY', 'y')]
256 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_YAMA', 'y')]
257 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_LANDLOCK', 'y')]
258 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DISABLE', 'is not set')]
259 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_BOOTPARAM', 'is not set')]
260 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_SELINUX_DEVELOP', 'is not set')]
261 l += [KconfigCheck('security_policy', 'kspp', 'SECURITY_WRITABLE_HOOKS', 'is not set')] # refers to SECURITY_SELINUX_DISABLE
262 l += [KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_SELINUX_DEBUG', 'is not set')]
263 l += [OR(KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_SELINUX', 'y'),
264 KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_APPARMOR', 'y'),
265 KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_SMACK', 'y'),
266 KconfigCheck('security_policy', 'a13xp0p0v', 'SECURITY_TOMOYO', 'y'))] # one of major LSMs implementing MAC
268 # 'cut_attack_surface', 'defconfig'
269 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'SECCOMP', 'y')]
270 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'SECCOMP_FILTER', 'y')]
271 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'BPF_UNPRIV_DEFAULT_OFF', 'y'),
272 bpf_syscall_not_set)] # see unprivileged_bpf_disabled
273 if arch in ('X86_64', 'ARM64', 'X86_32'):
274 l += [OR(KconfigCheck('cut_attack_surface', 'defconfig', 'STRICT_DEVMEM', 'y'),
275 devmem_not_set)] # refers to LOCKDOWN
276 if arch in ('X86_64', 'X86_32'):
277 l += [KconfigCheck('cut_attack_surface', 'defconfig', 'X86_INTEL_TSX_MODE_OFF', 'y')] # tsx=off
279 # 'cut_attack_surface', 'kspp'
280 l += [KconfigCheck('cut_attack_surface', 'kspp', 'SECURITY_DMESG_RESTRICT', 'y')]
281 l += [KconfigCheck('cut_attack_surface', 'kspp', 'ACPI_CUSTOM_METHOD', 'is not set')] # refers to LOCKDOWN
282 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_BRK', 'is not set')]
283 l += [KconfigCheck('cut_attack_surface', 'kspp', 'DEVKMEM', 'is not set')] # refers to LOCKDOWN
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 += [KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_TIOCSTI', 'is not set')]
298 l += [modules_not_set]
299 l += [devmem_not_set]
300 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'IO_STRICT_DEVMEM', 'y'),
301 devmem_not_set)] # refers to LOCKDOWN
302 l += [AND(KconfigCheck('cut_attack_surface', 'kspp', 'LDISC_AUTOLOAD', 'is not set'),
303 KconfigCheck('cut_attack_surface', 'kspp', 'LDISC_AUTOLOAD', 'is present'))]
304 if arch in ('X86_64', 'X86_32'):
305 l += [KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set')]
306 # CONFIG_COMPAT_VDSO disabled ASLR of vDSO only on X86_64 and X86_32;
307 # on ARM64 this option has different meaning
309 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'X86_VSYSCALL_EMULATION', 'is not set'),
310 KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_VSYSCALL_NONE', 'y'))]
311 # disabling X86_VSYSCALL_EMULATION turns vsyscall off completely,
312 # and LEGACY_VSYSCALL_NONE can be changed at boot time via the cmdline parameter
314 l += [OR(KconfigCheck('cut_attack_surface', 'kspp', 'STRICT_DEVMEM', 'y'),
315 devmem_not_set)] # refers to LOCKDOWN
317 # 'cut_attack_surface', 'grsec'
318 l += [KconfigCheck('cut_attack_surface', 'grsec', 'ZSMALLOC_STAT', 'is not set')]
319 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PAGE_OWNER', 'is not set')]
320 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_KMEMLEAK', 'is not set')]
321 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BINFMT_AOUT', 'is not set')]
322 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KPROBE_EVENTS', 'is not set')]
323 l += [KconfigCheck('cut_attack_surface', 'grsec', 'UPROBE_EVENTS', 'is not set')]
324 l += [KconfigCheck('cut_attack_surface', 'grsec', 'GENERIC_TRACER', 'is not set')] # refers to LOCKDOWN
325 l += [KconfigCheck('cut_attack_surface', 'grsec', 'FUNCTION_TRACER', 'is not set')]
326 l += [KconfigCheck('cut_attack_surface', 'grsec', 'STACK_TRACER', 'is not set')]
327 l += [KconfigCheck('cut_attack_surface', 'grsec', 'HIST_TRIGGERS', 'is not set')]
328 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BLK_DEV_IO_TRACE', 'is not set')]
329 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROC_VMCORE', 'is not set')]
330 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROC_PAGE_MONITOR', 'is not set')]
331 l += [KconfigCheck('cut_attack_surface', 'grsec', 'USELIB', 'is not set')]
332 l += [KconfigCheck('cut_attack_surface', 'grsec', 'CHECKPOINT_RESTORE', 'is not set')]
333 l += [KconfigCheck('cut_attack_surface', 'grsec', 'USERFAULTFD', 'is not set')]
334 l += [KconfigCheck('cut_attack_surface', 'grsec', 'HWPOISON_INJECT', 'is not set')]
335 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MEM_SOFT_DIRTY', 'is not set')]
336 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEVPORT', 'is not set')] # refers to LOCKDOWN
337 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_FS', 'is not set')] # refers to LOCKDOWN
338 l += [KconfigCheck('cut_attack_surface', 'grsec', 'NOTIFIER_ERROR_INJECTION', 'is not set')]
339 l += [KconfigCheck('cut_attack_surface', 'grsec', 'FAIL_FUTEX', 'is not set')]
340 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PUNIT_ATOM_DEBUG', 'is not set')]
341 l += [KconfigCheck('cut_attack_surface', 'grsec', 'ACPI_CONFIGFS', 'is not set')]
342 l += [KconfigCheck('cut_attack_surface', 'grsec', 'EDAC_DEBUG', 'is not set')]
343 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DRM_I915_DEBUG', 'is not set')]
344 l += [KconfigCheck('cut_attack_surface', 'grsec', 'BCACHE_CLOSURES_DEBUG', 'is not set')]
345 l += [KconfigCheck('cut_attack_surface', 'grsec', 'DVB_C8SECTPFE', 'is not set')]
346 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MTD_SLRAM', 'is not set')]
347 l += [KconfigCheck('cut_attack_surface', 'grsec', 'MTD_PHRAM', 'is not set')]
348 l += [KconfigCheck('cut_attack_surface', 'grsec', 'IO_URING', 'is not set')]
349 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KCMP', 'is not set')]
350 l += [KconfigCheck('cut_attack_surface', 'grsec', 'RSEQ', 'is not set')]
351 l += [KconfigCheck('cut_attack_surface', 'grsec', 'LATENCYTOP', 'is not set')]
352 l += [KconfigCheck('cut_attack_surface', 'grsec', 'KCOV', 'is not set')]
353 l += [KconfigCheck('cut_attack_surface', 'grsec', 'PROVIDE_OHCI1394_DMA_INIT', 'is not set')]
354 l += [KconfigCheck('cut_attack_surface', 'grsec', 'SUNRPC_DEBUG', 'is not set')]
355 l += [AND(KconfigCheck('cut_attack_surface', 'grsec', 'PTDUMP_DEBUGFS', 'is not set'),
356 KconfigCheck('cut_attack_surface', 'grsec', 'X86_PTDUMP', 'is not set'))]
358 # 'cut_attack_surface', 'maintainer'
359 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'DRM_LEGACY', 'is not set')] # recommended by Daniel Vetter in /issues/38
360 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'FB', 'is not set')] # recommended by Daniel Vetter in /issues/38
361 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'VT', 'is not set')] # recommended by Daniel Vetter in /issues/38
362 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD', 'is not set')] # recommended by Denis Efremov in /pull/54
363 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'BLK_DEV_FD_RAWCMD', 'is not set')] # recommended by Denis Efremov in /pull/62
364 l += [KconfigCheck('cut_attack_surface', 'maintainer', 'NOUVEAU_LEGACY_CTX_SUPPORT', 'is not set')]
365 # recommended by Dave Airlie in kernel commit b30a43ac7132cdda
367 # 'cut_attack_surface', 'clipos'
368 l += [KconfigCheck('cut_attack_surface', 'clipos', 'STAGING', 'is not set')]
369 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KSM', 'is not set')] # to prevent FLUSH+RELOAD attack
370 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KALLSYMS', 'is not set')]
371 l += [KconfigCheck('cut_attack_surface', 'clipos', 'MAGIC_SYSRQ', 'is not set')]
372 l += [KconfigCheck('cut_attack_surface', 'clipos', 'KEXEC_FILE', 'is not set')] # refers to LOCKDOWN (permissive)
373 l += [KconfigCheck('cut_attack_surface', 'clipos', 'USER_NS', 'is not set')] # user.max_user_namespaces=0
374 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_CPUID', 'is not set')]
375 l += [KconfigCheck('cut_attack_surface', 'clipos', 'X86_IOPL_IOPERM', 'is not set')] # refers to LOCKDOWN
376 l += [KconfigCheck('cut_attack_surface', 'clipos', 'ACPI_TABLE_UPGRADE', 'is not set')] # refers to LOCKDOWN
377 l += [KconfigCheck('cut_attack_surface', 'clipos', 'EFI_CUSTOM_SSDT_OVERLAYS', 'is not set')]
378 l += [KconfigCheck('cut_attack_surface', 'clipos', 'AIO', 'is not set')]
379 # l += [KconfigCheck('cut_attack_surface', 'clipos', 'IKCONFIG', 'is not set')] # no, IKCONFIG is needed for this check :)
381 # 'cut_attack_surface', 'lockdown'
382 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'EFI_TEST', 'is not set')] # refers to LOCKDOWN
383 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'MMIOTRACE_TEST', 'is not set')] # refers to LOCKDOWN
384 l += [KconfigCheck('cut_attack_surface', 'lockdown', 'KPROBES', 'is not set')] # refers to LOCKDOWN
385 l += [bpf_syscall_not_set] # refers to LOCKDOWN
387 # 'cut_attack_surface', 'a13xp0p0v'
388 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'MMIOTRACE', 'is not set')] # refers to LOCKDOWN (permissive)
389 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'LIVEPATCH', 'is not set')]
390 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'IP_DCCP', 'is not set')]
391 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'IP_SCTP', 'is not set')]
392 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'FTRACE', 'is not set')] # refers to LOCKDOWN
393 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'VIDEO_VIVID', 'is not set')]
394 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'INPUT_EVBUG', 'is not set')] # Can be used as a keylogger
395 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'KGDB', 'is not set')]
396 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'CORESIGHT', 'is not set')]
397 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'XFS_SUPPORT_V4', 'is not set')]
398 l += [OR(KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'TRIM_UNUSED_KSYMS', 'y'),
400 l += [KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'MODULE_FORCE_LOAD', 'is not set')]
404 l += [KconfigCheck('harden_userspace', 'defconfig', 'ARM64_PTR_AUTH', 'y')]
405 l += [KconfigCheck('harden_userspace', 'defconfig', 'ARM64_BTI', 'y')]
406 if arch in ('ARM', 'X86_32'):
407 l += [KconfigCheck('harden_userspace', 'defconfig', 'VMSPLIT_3G', 'y')]
408 l += [KconfigCheck('harden_userspace', 'clipos', 'COREDUMP', 'is not set')]
409 l += [KconfigCheck('harden_userspace', 'a13xp0p0v', 'ARCH_MMAP_RND_BITS', 'MAX')] # 'MAX' value is refined using ARCH_MMAP_RND_BITS_MAX
412 def add_cmdline_checks(l, arch):
413 assert(arch), 'empty arch'
415 # Calling the CmdlineCheck class constructor:
416 # CmdlineCheck(reason, decision, name, expected)
418 # [!] Don't add CmdlineChecks in add_kconfig_checks() to avoid wrong results
419 # when the tool doesn't check the cmdline.
421 # [!] Make sure that values of the options in CmdlineChecks need normalization.
422 # For more info see normalize_cmdline_options().
424 # A common pattern for checking the 'param_x' cmdline parameter
425 # that __overrides__ the 'PARAM_X_DEFAULT' kconfig option:
426 # l += [OR(CmdlineCheck(reason, decision, 'param_x', '1'),
427 # AND(KconfigCheck(reason, decision, 'PARAM_X_DEFAULT_ON', 'y'),
428 # CmdlineCheck(reason, decision, 'param_x, 'is not set')))]
430 # Here we don't check the kconfig options or minimal kernel version
431 # required for the cmdline parameters. That would make the checks
432 # very complex and not give a 100% guarantee anyway.
434 # 'self_protection', 'defconfig'
435 l += [CmdlineCheck('self_protection', 'defconfig', 'nosmep', 'is not set')]
436 l += [CmdlineCheck('self_protection', 'defconfig', 'nosmap', 'is not set')]
437 l += [CmdlineCheck('self_protection', 'defconfig', 'nokaslr', 'is not set')]
438 l += [CmdlineCheck('self_protection', 'defconfig', 'nopti', 'is not set')]
439 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_v1', 'is not set')]
440 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_v2', 'is not set')]
441 l += [CmdlineCheck('self_protection', 'defconfig', 'nospectre_bhb', 'is not set')]
442 l += [CmdlineCheck('self_protection', 'defconfig', 'nospec_store_bypass_disable', 'is not set')]
443 l += [CmdlineCheck('self_protection', 'defconfig', 'dis_ucode_ldr', 'is not set')]
444 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nobti', 'is not set')]
445 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nopauth', 'is not set')]
446 l += [CmdlineCheck('self_protection', 'defconfig', 'arm64.nomte', 'is not set')]
447 if arch in ('X86_64', 'X86_32'):
448 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_v2', 'is not off'),
449 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
450 CmdlineCheck('self_protection', 'defconfig', 'spectre_v2', 'is not set')))]
451 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spectre_v2_user', 'is not off'),
452 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
453 CmdlineCheck('self_protection', 'defconfig', 'spectre_v2_user', 'is not set')))]
454 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spec_store_bypass_disable', 'is not off'),
455 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
456 CmdlineCheck('self_protection', 'defconfig', 'spec_store_bypass_disable', 'is not set')))]
457 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'l1tf', 'is not off'),
458 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
459 CmdlineCheck('self_protection', 'defconfig', 'l1tf', 'is not set')))]
460 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'mds', 'is not off'),
461 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
462 CmdlineCheck('self_protection', 'defconfig', 'mds', 'is not set')))]
463 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'tsx_async_abort', 'is not off'),
464 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
465 CmdlineCheck('self_protection', 'defconfig', 'tsx_async_abort', 'is not set')))]
466 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'srbds', 'is not off'),
467 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
468 CmdlineCheck('self_protection', 'defconfig', 'srbds', 'is not set')))]
469 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'mmio_stale_data', 'is not off'),
470 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
471 CmdlineCheck('self_protection', 'defconfig', 'mmio_stale_data', 'is not set')))]
472 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not off'),
473 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
474 CmdlineCheck('self_protection', 'defconfig', 'retbleed', 'is not set')))]
475 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'spec_rstack_overflow', 'is not off'),
476 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
477 CmdlineCheck('self_protection', 'defconfig', 'spec_rstack_overflow', 'is not set')))]
478 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'gather_data_sampling', 'is not off'),
479 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
480 CmdlineCheck('self_protection', 'defconfig', 'gather_data_sampling', 'is not set')))]
482 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not off'),
483 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
484 CmdlineCheck('self_protection', 'defconfig', 'kpti', 'is not set')))]
485 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'kernel'),
486 CmdlineCheck('self_protection', 'a13xp0p0v', 'ssbd', 'force-on'),
487 AND(CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt'),
488 CmdlineCheck('self_protection', 'defconfig', 'ssbd', 'is not set')))]
489 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'rodata', 'full'),
490 AND(KconfigCheck('self_protection', 'defconfig', 'RODATA_FULL_DEFAULT_ENABLED', 'y'),
491 CmdlineCheck('self_protection', 'defconfig', 'rodata', 'is not set')))]
493 l += [OR(CmdlineCheck('self_protection', 'defconfig', 'rodata', 'on'),
494 CmdlineCheck('self_protection', 'defconfig', 'rodata', 'is not set'))]
496 # 'self_protection', 'kspp'
497 l += [CmdlineCheck('self_protection', 'kspp', 'mitigations', 'auto,nosmt')]
498 l += [CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set')] # consequence of 'slab_nomerge' by kspp
499 l += [CmdlineCheck('self_protection', 'kspp', 'slub_merge', 'is not set')] # consequence of 'slab_nomerge' by kspp
500 l += [CmdlineCheck('self_protection', 'kspp', 'page_alloc.shuffle', '1')]
501 l += [OR(CmdlineCheck('self_protection', 'kspp', 'slab_nomerge', 'is present'),
502 AND(KconfigCheck('self_protection', 'clipos', 'SLAB_MERGE_DEFAULT', 'is not set'),
503 CmdlineCheck('self_protection', 'kspp', 'slab_merge', 'is not set'),
504 CmdlineCheck('self_protection', 'kspp', 'slub_merge', 'is not set')))]
505 l += [OR(CmdlineCheck('self_protection', 'kspp', 'init_on_alloc', '1'),
506 AND(KconfigCheck('self_protection', 'kspp', 'INIT_ON_ALLOC_DEFAULT_ON', 'y'),
507 CmdlineCheck('self_protection', 'kspp', 'init_on_alloc', 'is not set')))]
508 l += [OR(CmdlineCheck('self_protection', 'kspp', 'init_on_free', '1'),
509 AND(KconfigCheck('self_protection', 'kspp', 'INIT_ON_FREE_DEFAULT_ON', 'y'),
510 CmdlineCheck('self_protection', 'kspp', 'init_on_free', 'is not set')),
511 AND(CmdlineCheck('self_protection', 'kspp', 'page_poison', '1'),
512 KconfigCheck('self_protection', 'kspp', 'PAGE_POISONING_ZERO', 'y'),
513 CmdlineCheck('self_protection', 'kspp', 'slub_debug', 'P')))]
514 l += [OR(CmdlineCheck('self_protection', 'kspp', 'hardened_usercopy', '1'),
515 AND(KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY', 'y'),
516 CmdlineCheck('self_protection', 'kspp', 'hardened_usercopy', 'is not set')))]
517 l += [AND(CmdlineCheck('self_protection', 'kspp', 'slab_common.usercopy_fallback', 'is not set'),
518 KconfigCheck('self_protection', 'kspp', 'HARDENED_USERCOPY_FALLBACK', 'is not set'))]
519 # Consequence of the HARDENED_USERCOPY_FALLBACK check by kspp.
520 # Don't require slab_common.usercopy_fallback=0,
521 # since HARDENED_USERCOPY_FALLBACK was removed in Linux v5.16.
522 if arch in ('X86_64', 'ARM64', 'X86_32'):
523 l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.strict', '1'),
524 AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_DMA_STRICT', 'y'),
525 CmdlineCheck('self_protection', 'kspp', 'iommu.strict', 'is not set')))]
526 l += [OR(CmdlineCheck('self_protection', 'kspp', 'iommu.passthrough', '0'),
527 AND(KconfigCheck('self_protection', 'kspp', 'IOMMU_DEFAULT_PASSTHROUGH', 'is not set'),
528 CmdlineCheck('self_protection', 'kspp', 'iommu.passthrough', 'is not set')))]
529 l += [OR(CmdlineCheck('self_protection', 'kspp', 'randomize_kstack_offset', '1'),
530 AND(KconfigCheck('self_protection', 'kspp', 'RANDOMIZE_KSTACK_OFFSET_DEFAULT', 'y'),
531 CmdlineCheck('self_protection', 'kspp', 'randomize_kstack_offset', 'is not set')))]
532 if arch in ('X86_64', 'X86_32'):
533 l += [AND(CmdlineCheck('self_protection', 'kspp', 'pti', 'on'),
534 CmdlineCheck('self_protection', 'defconfig', 'nopti', 'is not set'))]
536 # 'self_protection', 'clipos'
537 if arch in ('X86_64', 'X86_32'):
538 l += [CmdlineCheck('self_protection', 'clipos', 'iommu', 'force')]
540 # 'self_protection', 'a13xp0p0v'
541 l += [OR(CmdlineCheck('self_protection', 'a13xp0p0v', 'kfence.sample_interval', 'is not off'),
542 AND(KconfigCheck('self_protection', 'a13xp0p0v', 'KFENCE_SAMPLE_INTERVAL', 'is not off'),
543 CmdlineCheck('self_protection', 'a13xp0p0v', 'kfence.sample_interval', 'is not set')))]
545 # 'cut_attack_surface', 'defconfig'
546 if arch in ('X86_64', 'X86_32'):
547 l += [OR(CmdlineCheck('cut_attack_surface', 'defconfig', 'tsx', 'off'),
548 AND(KconfigCheck('cut_attack_surface', 'defconfig', 'X86_INTEL_TSX_MODE_OFF', 'y'),
549 CmdlineCheck('cut_attack_surface', 'defconfig', 'tsx', 'is not set')))]
551 # 'cut_attack_surface', 'kspp'
552 l += [CmdlineCheck('cut_attack_surface', 'kspp', 'nosmt', 'is present')] # slow (high performance penalty)
554 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vsyscall', 'none'),
555 KconfigCheck('cut_attack_surface', 'kspp', 'X86_VSYSCALL_EMULATION', 'is not set'),
556 AND(KconfigCheck('cut_attack_surface', 'kspp', 'LEGACY_VSYSCALL_NONE', 'y'),
557 CmdlineCheck('cut_attack_surface', 'kspp', 'vsyscall', 'is not set')))]
558 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vdso32', '0'),
559 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', '1'),
560 AND(KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set'),
561 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', 'is not set')))] # the vdso32 parameter must not be 2
563 l += [OR(CmdlineCheck('cut_attack_surface', 'kspp', 'vdso32', '0'),
564 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso', '0'),
565 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', '1'),
566 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso', '1'),
567 AND(KconfigCheck('cut_attack_surface', 'kspp', 'COMPAT_VDSO', 'is not set'),
568 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso32', 'is not set'),
569 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'vdso', 'is not set')))] # the vdso and vdso32 parameters must not be 2
571 # 'cut_attack_surface', 'grsec'
572 # The cmdline checks compatible with the kconfig options disabled by grsecurity...
573 l += [OR(CmdlineCheck('cut_attack_surface', 'grsec', 'debugfs', 'off'),
574 KconfigCheck('cut_attack_surface', 'grsec', 'DEBUG_FS', 'is not set'))] # ... the end
576 # 'cut_attack_surface', 'a13xp0p0v'
577 l += [CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'sysrq_always_enabled', 'is not set')]
579 l += [OR(CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'ia32_emulation', '0'),
580 KconfigCheck('cut_attack_surface', 'kspp', 'IA32_EMULATION', 'is not set'),
581 AND(KconfigCheck('cut_attack_surface', 'a13xp0p0v', 'IA32_EMULATION_DEFAULT_DISABLED', 'y'),
582 CmdlineCheck('cut_attack_surface', 'a13xp0p0v', 'ia32_emulation', 'is not set')))]
585 l += [CmdlineCheck('harden_userspace', 'defconfig', 'norandmaps', 'is not set')]
588 no_kstrtobool_options = [
589 'debugfs', # See debugfs_kernel() in fs/debugfs/inode.c
590 'mitigations', # See mitigations_parse_cmdline() in kernel/cpu.c
591 'pti', # See pti_check_boottime_disable() in arch/x86/mm/pti.c
592 'spectre_v2', # See spectre_v2_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
593 'spectre_v2_user', # See spectre_v2_parse_user_cmdline() in arch/x86/kernel/cpu/bugs.c
594 'spec_store_bypass_disable', # See ssb_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
595 'l1tf', # See l1tf_cmdline() in arch/x86/kernel/cpu/bugs.c
596 'mds', # See mds_cmdline() in arch/x86/kernel/cpu/bugs.c
597 'tsx_async_abort', # See tsx_async_abort_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
598 'srbds', # See srbds_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
599 'mmio_stale_data', # See mmio_stale_data_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
600 'retbleed', # See retbleed_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
601 'rodata', # See set_debug_rodata() in init/main.c
602 'ssbd', # See parse_spectre_v4_param() in arch/arm64/kernel/proton-pack.c
603 'spec_rstack_overflow', # See srso_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
604 'gather_data_sampling', # See gds_parse_cmdline() in arch/x86/kernel/cpu/bugs.c
605 'slub_debug', # See setup_slub_debug() in mm/slub.c
606 'iommu', # See iommu_setup() in arch/x86/kernel/pci-dma.c
607 'vsyscall', # See vsyscall_setup() in arch/x86/entry/vsyscall/vsyscall_64.c
608 'vdso32', # See vdso32_setup() in arch/x86/entry/vdso/vdso32-setup.c
609 'vdso', # See vdso32_setup() in arch/x86/entry/vdso/vdso32-setup.c
610 'tsx' # See tsx_init() in arch/x86/kernel/cpu/tsx.c
614 def normalize_cmdline_options(option, value):
615 # Don't normalize the cmdline option values if
616 # the Linux kernel doesn't use kstrtobool() for them
617 if option in no_kstrtobool_options:
620 # Implement a limited part of the kstrtobool() logic
621 if value.lower() in ('1', 'on', 'y', 'yes', 't', 'true'):
623 if value.lower() in ('0', 'off', 'n', 'no', 'f', 'false'):
626 # Preserve unique values
630 # TODO: draft of security hardening sysctls:
631 # what about bpf_jit_enable?
632 # vm.mmap_min_addr has a good value
633 # nosmt sysfs control file
634 # vm.mmap_rnd_bits=max (?)
636 # abi.vsyscall32 (any value except 2)
637 # kernel.oops_limit (think about a proper value)
638 # kernel.warn_limit (think about a proper value)
639 # net.ipv4.tcp_syncookies=1 (?)
641 def add_sysctl_checks(l, _arch):
642 # This function may be called with arch=None
644 # Calling the SysctlCheck class constructor:
645 # SysctlCheck(reason, decision, name, expected)
647 l += [SysctlCheck('self_protection', 'kspp', 'net.core.bpf_jit_harden', '2')]
649 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.dmesg_restrict', '1')]
650 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.perf_event_paranoid', '3')] # with a custom patch, see https://lwn.net/Articles/696216/
651 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.kexec_load_disabled', '1')]
652 l += [SysctlCheck('cut_attack_surface', 'kspp', 'user.max_user_namespaces', '0')]
653 l += [SysctlCheck('cut_attack_surface', 'kspp', 'dev.tty.ldisc_autoload', '0')]
654 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.unprivileged_bpf_disabled', '1')]
655 l += [SysctlCheck('cut_attack_surface', 'kspp', 'kernel.kptr_restrict', '2')]
656 l += [SysctlCheck('cut_attack_surface', 'kspp', 'dev.tty.legacy_tiocsti', '0')]
657 l += [SysctlCheck('cut_attack_surface', 'kspp', 'vm.unprivileged_userfaultfd', '0')]
658 # At first, it disabled unprivileged userfaultfd,
659 # and since v5.11 it enables unprivileged userfaultfd for user-mode only.
661 l += [SysctlCheck('cut_attack_surface', 'clipos', 'kernel.modules_disabled', '1')] # radical, but may be useful in some cases
663 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_symlinks', '1')]
664 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_hardlinks', '1')]
665 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_fifos', '2')]
666 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.protected_regular', '2')]
667 l += [SysctlCheck('harden_userspace', 'kspp', 'fs.suid_dumpable', '0')]
668 l += [SysctlCheck('harden_userspace', 'kspp', 'kernel.randomize_va_space', '2')]
669 l += [SysctlCheck('harden_userspace', 'kspp', 'kernel.yama.ptrace_scope', '3')]