1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
-- This configuration file is licensed under the CC0 license.
-- Do whatever you want with it.
--
-- This is an example of how to use autokernel's capabilites for a hardening module.
-- It is designed to harden many aspects of the kernel based on choices
-- taken from several projects:
--
-- - [KSSP](https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project/Recommended_Settings)
-- - [CLIP OS](https://docs.clip-os.org/clipos/kernel.html#configuration)
-- - [kconfig-hardened-check](https://github.com/a13xp0p0v/kconfig-hardened-check)
--
-- After including this module be sure to set MODULE_SIG_KEY "path/to/sigining_key.pem".
-- In practice, this module should be modularized further.
local cmdline = ""
local
-- This unlocks extra configuration options we need
EXPERT
-- Required for several options. At best place outside of this module.
PCI
PCI_MSI
NET
INET
-- Don't allow direct access to physical memory.
-- The /dev/mem device should not be required by any user application nowadays.
DEVMEM
if MODULES:
-- Dangerous; enabling this allows direct physical memory writing.
ACPI_CUSTOM_METHOD
-- Dangerous; enabling this disables brk ASLR.
COMPAT_BRK
-- Dangerous; enabling this allows direct kernel memory writing.
if kernel_version <= ver
-- Dangerous; exposes kernel text image layout.
PROC_KCORE
-- Dangerous; enabling this disables VDSO ASLR.
COMPAT_VDSO
-- Dangerous; Disable the kexec() system call to prevent an already-root
-- attacker from rebooting on an untrusted kernel.
KEXEC
KEXEC_FILE
-- Dangerous; enabling this allows replacement of running kernel.
HIBERNATION
-- We do not want our kernel to support miscellaneous binary classes.
-- ELF binaries and interpreted scripts starting with a shebang are enough
-- Also easily confused by misconfigured userspace, keep off.
BINFMT_MISC
-- Also disable a.out/ECOFF format. (This is unrelated to a.out files
-- generated by gcc and alike, which are ELF files)
BINFMT_AOUT
-- Use the modern PTY interface (devpts) only.
LEGACY_PTYS
-- The userfaultfd() system call adds attack surface and can make heap sprays easier.
-- Note that the vm.unprivileged_userfaultfd sysctl can also be used to restrict the
-- use of this system call to privileged users.
if kernel_version >= ver
-- Disable the uselib system call, which is not needed on systems with a modern libc
USELIB
-- The /dev/port device should not be used anymore by userspace,
-- and it could increase the kernel attack surface.
DEVPORT
-- Enabling this feature can make cache side-channel attacks such
-- as FLUSH+RELOAD much easier to carry out.
KSM
-- Disable kprobes (allow callbacks on any kernel function)
KPROBES
-- Symbols are only useful for debug and attack purposes.
KALLSYMS
-- User namespaces can be useful for some use cases but even more
-- to an attacker. Optional because required by systemd.
--USER_NS "n"
-- Do not export ZSMALLOC statistics
ZSMALLOC_STAT
-- Do not track page owners.
PAGE_OWNER
-- Disable exporting crashed kernel images through /proc/vmcore
PROC_VMCORE
-- Disable debug_fs
DEBUG_FS
-- Disable kernel live-patching
LIVEPATCH
-- Do not automatically load any line discipline that is in a kernel module
-- when an unprivileged user asks for it.
if kernel_version >= ver
-- Disable exporting pagetable layout to prevent information leak.
if kernel_version >= ver
-- Prevent potential further exploitation of a bug by immediately panicking the kernel.
PANIC_ON_OOPS
-- Report BUG() conditions and kill the offending process.
BUG
if kernel_version >= ver
-- Enable hardware random
HW_RANDOM
HW_RANDOM_INTEL
HW_RANDOM_AMD
-- Enable Expose the TPM’s Random Number Generator (RNG) as a Hardware RNG (HWRNG) and
-- expose the TPM’s Random Number Generator (RNG) as a Hardware RNG (HWRNG)
-- device, allowing the kernel to collect randomness from it. See documentation
-- of RANDOM_TRUST_CPU and the rng_core.default_quality command line parameter
-- for supplementary information.
TCG_TPM
HW_RANDOM_TPM
-- Increase trust in the TPM’s HWRNG to robustly and fastly initialize Linux’s CSPRNG
-- by crediting half of the entropy it provides.
add_cmdline
-- Enable the auditing infrastructure.
AUDIT
-- Make sure kernel page tables have safe permissions.
if kernel_version < ver
-- This is useful even in a production kernel to enable further configuration options
-- that have security benefits.
DEBUG_KERNEL
-- Enable sanity checks in virtual to page code.
DEBUG_VIRTUAL
-- Ensure kernel page tables have strict permissions.
if kernel_version >= ver and ARCH_OPTIONAL_KERNEL_RWX:
-- Check and report any dangerous memory mapping permissions, i.e., both writable and
-- executable kernel pages.
if kernel_version >= ver
-- Use strong stack protector for best stack canary coverage.
if kernel_version >= ver
-- If you must have DEVMEM, at least enable STRICT mode
if DEVMEM:
-- Provides some protections against SYN flooding.
SYN_COOKIES
-- Perform additional validation of various commonly targeted structures.
DEBUG_CREDENTIALS
DEBUG_NOTIFIERS
DEBUG_LIST
DEBUG_SG
if kernel_version >= ver
SCHED_STACK_END_CHECK
-- Provide userspace with seccomp BPF API for syscall attack surface reduction.
SECCOMP
-- Enable us to choose different security modules.
SECURITY
-- -- Enable SELinux for hosts that intend to leverage it in their security model.
-- SECURITY_SELINUX "y"
-- -- We do not need SELinux to be disableable by a boot parameter.
-- SECURITY_SELINUX_BOOTPARAM "n"
-- -- We do not want SELinux to be disabled. In addition, keeping this option off makes
-- -- LSM structures such as security hooks read-only.
-- SECURITY_SELINUX_DISABLE "n"
-- -- For now, but should eventually be set to n.
-- SECURITY_SELINUX_DEVELOP "y"
-- Enables ptrace scope restrictions.
SECURITY_YAMA
-- Perform usercopy bounds checking. (And disable fallback to gain full whitelist enforcement.)
if kernel_version >= ver
-- Merging SLAB pages can make heap exploitation easier
if kernel_version >= ver
-- Randomize allocator freelists.
if kernel_version >= ver
-- Harden slab metadata.
if kernel_version >= ver
-- Randomize high-order page allocation freelist.
-- Page allocator randomization is primarily a performance improvement for direct-mapped
-- memory-side-cache utilization, but it does reduce the predictability of page allocations
-- and thus complements SLAB_FREELIST_RANDOM. The page_alloc.shuffle=1 parameter needs to
-- be added to the kernel command line.
if kernel_version >= ver
if kernel_version >= ver
-- Initialize all stack variables on function entry, with
if kernel_version >= ver kernel_version >= ver kernel_version >= ver and HAVE_GCC_PLUGINS:
-- Virtually-mapped stacks benefit from guard pages,
-- thus making kernel stack overflows harder to exploit.
if kernel_version >= ver
-- Perform extensive checks on reference counting. (Unconditionally enabled since 5.5)
if kernel_version >= ver and kernel_version < ver
-- Check for memory copies that might overflow a structure in str*() and
-- mem*() functions both at build-time and run-time.
if kernel_version >= ver
if kernel_version >= ver and HAVE_GCC_PLUGINS:
-- Needed to benefit from microcode updates and thus security fixes
-- (e.g., additional Intel pseudo-MSRs to be used by the kernel as a
-- mitigation for various speculative execution vulnerabilities).
MICROCODE
-- Retpolines are needed to protect against Spectre v2.
if kernel_version >= ver
-- Always enable spectre_v2 mitigation, even on CPUs that report they are
-- not affected. This implies spectre_v2_user=on, which enables the mitigation
-- against user space to user space task attacks (namely IBPB and STIBP when
-- available and relevant).
add_cmdline
-- Always enable spectre_v4 mitigation
add_cmdline
-- Mitigations for the Microarchitectural Data Sampling (MDS) vulnerability
-- on intel processors, and optionally allow disabling SMT (Simultaneous multithreading)
-- to do so.
add_cmdline
-- If you want to disable hyperthreading, use this line instead.
--add_cmdline "mds=full,nosmt"
-- The IOMMU allows for protecting the system’s main memory from arbitrary
-- accesses from devices (e.g., DMA attacks). Note that this is related to
-- hardware features.
IOMMU_SUPPORT
INTEL_IOMMU
if kernel_version >= ver
INTEL_IOMMU_DEFAULT_ON
AMD_IOMMU
AMD_IOMMU_V2
-- Always enable iommu
add_cmdline
-- Prevent unprivileged users from gathering information from the kernel log
-- buffer via dmesg(8). Note that this still can be overridden through the
-- kernel.dmesg_restrict sysctl.
SECURITY_DMESG_RESTRICT
if kernel_version >= ver
-- In order to work properly, this mitigation requires userspace support
-- that is not commonly configured. You can enable this yourself if you want
-- provide the support on your system.
if kernel_version >= ver
-- This restricts loading modules from one file system only. Must be enabled via cmdline
-- or SECURITY_LOADPIN_ENFORCE=y, which could be used if there is no initramfs.
if kernel_version >= ver
if kernel_version >= ver
-- Use maximum number of randomized bits for the mmap base address on x86_64.
if kernel_version >= ver
-- The list of security modules to enable, in load order.
if kernel_version >= ver
if X86:
if X86_64: X86: os. == "arm64" os. == "arm"
-- set cmdline (in practice better return the cmdline and set this in your own config,
-- so you can add more if required)
CMDLINE