Update CLIP OS doc
[kconfig-hardened-check.git] / config_files / distros / clipos_kernel_doc.txt
1 .. Copyright © 2018 ANSSI.
2    CLIP OS is a trademark of the French Republic.
3    Content licensed under the Open License version 2.0 as published by Etalab
4    (French task force for Open Data).
5
6 .. _kernel:
7
8 Kernel
9 ======
10
11 The CLIP OS kernel is based on Linux. It also integrates:
12
13 * existing hardening patches that are not upstream yet and that we consider
14   relevant to our security model;
15 * developments made for previous CLIP OS versions that we have not upstreamed
16   yet (or that cannot be);
17 * entirely new functionalities that have not been upstreamed yet (or that
18   cannot be).
19
20 Objectives
21 ----------
22
23 As the core of a hardened operating system, the CLIP OS kernel is particularly
24 responsible for:
25
26 * providing **robust security mechanisms** to higher levels of the operating
27   system, such as reliable isolation primitives;
28 * maintaining maximal **trust in hardware resources**;
29 * guaranteeing its **own protection** against various threats.
30
31 Configuration
32 -------------
33
34 In this section we discuss our security-relevant configuration choices for
35 the CLIP OS kernel. Before starting, it is worth mentioning that:
36
37 * We do our best to **limit the number of kernel modules**.
38
39   In other words, as many modules as possible should be built-in. Modules are
40   only used when needed either for the initramfs or to ease the automation of
41   the deployment of CLIP OS on multiple different machines (for the moment, we
42   only target a QEMU-KVM guest). This is particularly important as module
43   loading is disabled after CLIP OS startup.
44
45 * We **focus on a secure configuration**. The remaining of the configuration
46   is minimal and it is your job to tune it for your machines and use cases.
47
48 * CLIP OS only supports the x86-64 architecture for now.
49
50 * Running 32-bit programs is voluntarily unsupported. Should you change that
51   in your custom kernel, keep in mind that it requires further attention when
52   configuring it (e.g., ensure that ``CONFIG_COMPAT_VDSO=n``).
53
54 * Many options that are not useful to us are disabled in order to cut attack
55   surface. As they are not all detailed below, please see
56   ``src/portage/clip/sys-kernel/clipos-kernel/files/config.d/blacklist`` for an
57   exhaustive list of the ones we **explicitly** disable.
58
59 General setup
60 ~~~~~~~~~~~~~
61
62 .. describe:: CONFIG_AUDIT=y
63
64    CLIP OS will need the auditing infrastructure.
65
66 .. describe:: CONFIG_IKCONFIG=n
67               CONFIG_IKHEADERS=n
68
69    We do not need ``.config`` to be available at runtime, neither do we need
70    access to kernel headers through *sysfs*.
71
72 .. describe:: CONFIG_KALLSYMS=n
73
74    Symbols are only useful for debug and attack purposes.
75
76 .. describe:: CONFIG_USERFAULTFD=n
77
78    The ``userfaultfd()`` system call adds attack surface and can `make heap
79    sprays easier <https://duasynt.com/blog/linux-kernel-heap-spray>`_. Note
80    that the ``vm.unprivileged_userfaultfd`` sysctl can also be used to restrict
81    the use of this system call to privileged users.
82
83 .. describe:: CONFIG_EXPERT=y
84
85    This unlocks additional configuration options we need.
86
87 .. ---
88
89 .. describe:: CONFIG_USER_NS=n
90
91    User namespaces can be useful for some use cases but even more to an
92    attacker. We choose to disable them for the moment, but we could also enable
93    them and use the ``kernel.unprivileged_userns_clone`` sysctl provided by
94    linux-hardened to disable their unprivileged use.
95
96 .. ---
97
98 .. describe:: CONFIG_SLUB_DEBUG=y
99
100    Allow allocator validation checking to be enabled.
101
102 .. describe:: CONFIG_SLAB_MERGE_DEFAULT=n
103
104    Merging SLAB caches can make heap exploitation easier.
105
106 .. describe:: CONFIG_SLAB_FREELIST_RANDOM=y
107
108    Randomize allocator freelists
109
110 .. describe:: CONFIG_SLAB_FREELIST_HARDENED=y
111
112    Harden slab metadata
113
114 .. describe:: CONFIG_SLAB_CANARY=y
115
116    Place canaries at the end of slab allocations. [linux-hardened]_
117
118 .. ---
119
120 .. describe:: CONFIG_SHUFFLE_PAGE_ALLOCATOR=y
121
122    Page allocator randomization is primarily a performance improvement for
123    direct-mapped memory-side-cache utilization, but it does reduce the
124    predictability of page allocations and thus complements
125    ``SLAB_FREELIST_RANDOM``. The ``page_alloc.shuffle=1`` parameter needs to be
126    added to the kernel command line.
127
128 .. ---
129
130 .. describe:: CONFIG_COMPAT_BRK=n
131
132    Enabling this would disable brk ASLR.
133
134 .. ---
135
136 .. describe:: CONFIG_GCC_PLUGINS=y
137
138    Enable GCC plugins, some of which are security-relevant; GCC 4.7 at least is
139    required.
140
141    .. describe:: CONFIG_GCC_PLUGIN_LATENT_ENTROPY=y
142
143       Instrument some kernel code to gather additional (but not
144       cryptographically secure) entropy at boot time.
145
146    .. describe:: CONFIG_GCC_PLUGIN_STRUCTLEAK=y
147                  CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=y
148
149       Prevent potential information leakage by forcing zero-initialization of:
150
151         - structures on the stack containing userspace addresses;
152         - any stack variable (thus including structures) that may be passed by
153           reference and has not already been explicitly initialized.
154
155       This is particularly important to prevent trivial bypassing of KASLR.
156
157    .. describe:: CONFIG_GCC_PLUGIN_RANDSTRUCT=y
158
159       Randomize layout of sensitive kernel structures. Exploits targeting such
160       structures then require an additional information leak vulnerability.
161
162    .. describe:: CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE=n
163
164       Do not weaken structure randomization
165
166 .. ---
167
168 .. describe:: CONFIG_ARCH_MMAP_RND_BITS=32
169
170    Use maximum number of randomized bits for the mmap base address on x86_64.
171    Note that thanks to a linux-hardened patch, this also impacts the number of
172    randomized bits for the stack base address.
173
174 .. ---
175
176 .. describe:: CONFIG_STACKPROTECTOR=y
177               CONFIG_STACKPROTECTOR_STRONG=y
178
179    Use ``-fstack-protector-strong`` for best stack canary coverage; GCC 4.9 at
180    least is required.
181
182 .. describe:: CONFIG_VMAP_STACK=y
183
184    Virtually-mapped stacks benefit from guard pages, thus making kernel stack
185    overflows harder to exploit.
186
187 .. describe:: CONFIG_REFCOUNT_FULL=y
188
189    Do extensive checks on reference counting to prevent use-after-free
190    conditions. Without this option, on x86, there already is a fast
191    assembly-based protection based on the PaX implementation but it does not
192    cover all cases.
193
194 .. ---
195
196 .. describe:: CONFIG_STRICT_MODULE_RWX=y
197
198    Enforce strict memory mappings permissions for loadable kernel modules.
199
200 .. ---
201
202 Although CLIP OS stores kernel modules in a read-only rootfs whose integrity is
203 guaranteed by dm-verity, we still enable and enforce module signing as an
204 additional layer of security:
205
206  .. describe:: CONFIG_MODULE_SIG=y
207                CONFIG_MODULE_SIG_FORCE=y
208                CONFIG_MODULE_SIG_ALL=y
209                CONFIG_MODULE_SIG_SHA512=y
210                CONFIG_MODULE_SIG_HASH="sha512"
211
212 .. ---
213
214 .. describe:: CONFIG_INIT_STACK_ALL=n
215
216    This option requires compiler support that is currently only available in
217    Clang.
218
219 Processor type and features
220 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
221
222 .. describe:: CONFIG_RETPOLINE=y
223
224    Retpolines are needed to protect against Spectre v2. GCC 7.3.0 or higher is
225    required.
226
227 .. describe:: CONFIG_LEGACY_VSYSCALL_NONE=y
228
229    The vsyscall table is not required anymore by libc and is a fixed-position
230    potential source of ROP gadgets.
231
232 .. describe:: CONFIG_X86_VSYSCALL_EMULATE=n
233               CONFIG_LEGACY_VSYSCALL_XONLY=n
234
235    See above.
236
237 .. describe:: CONFIG_MICROCODE=y
238
239    Needed to benefit from microcode updates and thus security fixes (e.g.,
240    additional Intel pseudo-MSRs to be used by the kernel as a mitigation for
241    various speculative execution vulnerabilities).
242
243 .. describe:: CONFIG_X86_MSR=n
244               CONFIG_X86_CPUID=n
245
246    Enabling those features would only present userspace with more attack
247    surface.
248
249 .. describe:: CONFIG_KSM=n
250
251    Enabling this feature can make cache side-channel attacks such as
252    FLUSH+RELOAD much easier to carry out.
253
254 .. ---
255
256 .. describe:: CONFIG_DEFAULT_MMAP_MIN_ADDR=65536
257
258    This should in particular be non-zero to prevent the exploitation of kernel
259    NULL pointer bugs.
260
261 .. describe:: CONFIG_MTRR=y
262
263    Memory Type Range Registers can make speculative execution bugs a bit harder
264    to exploit.
265
266 .. describe:: CONFIG_X86_PAT=y
267
268    Page Attribute Tables are the modern equivalents of MTRRs, which we
269    described above.
270
271 .. describe:: CONFIG_ARCH_RANDOM=y
272
273    Enable the RDRAND instruction to benefit from a secure hardware RNG if
274    supported. See also ``CONFIG_RANDOM_TRUST_CPU``.
275
276 .. describe:: CONFIG_X86_SMAP=y
277
278    Enable Supervisor Mode Access Prevention to prevent ret2usr exploitation
279    techniques.
280
281 .. describe:: CONFIG_X86_INTEL_UMIP=y
282
283    Enable User Mode Instruction Prevention. Note that hardware supporting this
284    feature is not common yet.
285
286 .. describe:: CONFIG_X86_INTEL_MPX=n
287
288    Intel Memory Protection Extensions add hardware assistance to memory
289    protection. Compiler support is required but is deprecated in GCC 8 and will
290    probably be dropped in GCC 9.
291
292 .. describe:: CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=n
293
294    Memory Protection Keys are a promising feature but they are still not
295    supported on current hardware.
296
297 .. describe:: CONFIG_X86_INTEL_TSX_MODE_OFF=y
298
299    Set the default value of the ``tsx`` kernel parameter to ``off``.
300
301 .. ---
302
303 Enable the **seccomp** BPF userspace API for syscall attack surface reduction:
304
305   .. describe:: CONFIG_SECCOMP=y
306                 CONFIG_SECCOMP_FILTER=y
307
308 .. ---
309
310 .. describe:: CONFIG_RANDOMIZE_BASE=y
311
312    While this may be seen as a `controversial
313    <https://grsecurity.net/kaslr_an_exercise_in_cargo_cult_security.php>`_
314    feature, it makes sense for CLIP OS. Indeed, KASLR may be defeated thanks to
315    the kernel interfaces that are available to an attacker, or through attacks
316    leveraging hardware vulnerabilities such as speculative and out-of-order
317    execution ones. However, CLIP OS follows the *defense in depth* principle
318    and an attack surface reduction approach. Thus, the following points make
319    KASLR relevant in the CLIP OS kernel:
320
321    * KASLR was initially designed to counter remote attacks but the strong
322      security model of CLIP OS (e.g., no sysfs mounts in most containers,
323      minimal procfs, no arbitrary code execution) makes a local attack
324      more complex to carry out.
325    * STRUCTLEAK, STACKLEAK, kptr_restrict and
326      ``CONFIG_SECURITY_DMESG_RESTRICT`` are enabled in CLIP OS.
327    * The CLIP OS kernel is custom-compiled (at least for a given deployment),
328      its image is unreadable to all users including privileged ones and updates
329      are end-to-end encrypted. This makes both the content and addresses of the
330      kernel image secret. Note that, however, the production kernel image is
331      currently part of an EFI binary and is not encrypted, causing it to be
332      accessible to a physical attacker. This will change in the future as we
333      will only use the kernel included in the EFI binary to boot and then
334      *kexec* to the real production kernel whose image will be located on an
335      encrypted disk partition.
336    * We enable ``CONFIG_PANIC_ON_OOPS`` by default so that the kernel
337      cannot recover from failed exploit attempts, thus preventing any brute
338      forcing.
339    * We enable Kernel Page Table Isolation, mitigating Meltdown and potential
340      other hardware information leakage. Variante 3a (Rogue System Register
341      Read) however remains an important threat to KASLR.
342
343 .. ---
344
345 .. describe:: CONFIG_RANDOMIZE_MEMORY=y
346
347    Most of the above explanations stand for that feature.
348
349 .. describe:: CONFIG_KEXEC=n
350               CONFIG_KEXEC_FILE=n
351
352    Disable the ``kexec()`` system call to prevent an already-root attacker from
353    rebooting on an untrusted kernel.
354
355 .. describe:: CONFIG_CRASH_DUMP=n
356
357    A crash dump can potentially provide an attacker with useful information.
358    However we disabled ``kexec()`` syscalls above thus this configuration
359    option should have no impact anyway.
360
361 .. ---
362
363 .. describe:: CONFIG_MODIFY_LDT_SYSCALL=n
364
365    This is not supposed to be needed by userspace applications and only
366    increases the kernel attack surface.
367
368 Power management and ACPI options
369 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
370
371 .. describe:: CONFIG_HIBERNATION=n
372
373    The CLIP OS swap partition is encrypted with an ephemeral key and thus
374    cannot support suspend to disk.
375
376 Firmware Drivers
377 ~~~~~~~~~~~~~~~~
378
379 .. describe:: CONFIG_RESET_ATTACK_MITIGATION=n
380
381    In order to work properly, this mitigation requires userspace support that
382    is currently not available in CLIP OS. Moreover, due to our use of Secure
383    Boot, Trusted Boot and the fact that machines running CLIP OS are expected
384    to lock their BIOS with a password, the type of *cold boot attacks* this
385    mitigation is supposed to thwart should not be an issue.
386
387 Executable file formats / Emulations
388 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
389
390 .. describe:: CONFIG_BINFMT_MISC=n
391
392    We do not want our kernel to support miscellaneous binary classes. ELF
393    binaries and interpreted scripts starting with a shebang are enough.
394
395 .. describe:: CONFIG_COREDUMP=n
396
397    Core dumps can provide an attacker with useful information.
398
399 Networking support
400 ~~~~~~~~~~~~~~~~~~
401
402 .. describe:: CONFIG_SYN_COOKIES=y
403
404    Enable TCP syncookies.
405
406 Device Drivers
407 ~~~~~~~~~~~~~~
408
409 .. describe:: CONFIG_HW_RANDOM_TPM=y
410
411    Expose the TPM's Random Number Generator (RNG) as a Hardware RNG (HWRNG)
412    device, allowing the kernel to collect randomness from it. See documentation
413    of ``CONFIG_RANDOM_TRUST_CPU`` and the ``rng_core.default_quality`` command
414    line parameter for supplementary information.
415
416 .. describe:: CONFIG_TCG_TPM=y
417
418    CLIP OS leverages the TPM to ensure :ref:`boot integrity <trusted_boot>`.
419
420 .. describe:: CONFIG_DEVMEM=n
421
422    The ``/dev/mem`` device should not be required by any user application
423    nowadays.
424
425    .. note::
426
427       If you must enable it, at least enable ``CONFIG_STRICT_DEVMEM`` and
428       ``CONFIG_IO_STRICT_DEVMEM`` to restrict at best access to this device.
429
430 .. describe:: CONFIG_DEVKMEM=n
431
432    This virtual device is only useful for debug purposes and is very dangerous
433    as it allows direct kernel memory writing (particularly useful for
434    rootkits).
435
436 .. describe:: CONFIG_LEGACY_PTYS=n
437
438    Use the modern PTY interface only.
439
440 .. describe:: CONFIG_LDISC_AUTOLOAD=n
441
442    Do not automatically load any line discipline that is in a kernel module
443    when an unprivileged user asks for it.
444
445 .. describe:: CONFIG_DEVPORT=n
446
447    The ``/dev/port`` device should not be used anymore by userspace, and it
448    could increase the kernel attack surface.
449
450 .. describe:: CONFIG_RANDOM_TRUST_CPU=n
451
452    Do not **credit** entropy generated by the CPU manufacturer's HWRNG and
453    included in Linux's entropy pool. Fast and robust initialization of Linux's
454    CSPRNG is instead achieved thanks to the TPM's HWRNG (see documentation of
455    ``CONFIG_HW_RANDOM_TPM`` and the ``rng_core.default_quality`` command line
456    parameter).
457
458 The IOMMU allows for protecting the system's main memory from arbitrary
459 accesses from devices (e.g., DMA attacks). Note that this is related to
460 hardware features. On a recent Intel machine, we enable the following:
461
462   .. describe:: CONFIG_IOMMU_SUPPORT=y
463                 CONFIG_INTEL_IOMMU=y
464                 CONFIG_INTEL_IOMMU_SVM=y
465                 CONFIG_INTEL_IOMMU_DEFAULT_ON=y
466
467 File systems
468 ~~~~~~~~~~~~
469
470 .. describe:: CONFIG_PROC_KCORE=n
471
472    Enabling this would provide an attacker with precious information on the
473    running kernel.
474
475 Kernel hacking
476 ~~~~~~~~~~~~~~
477
478 .. describe:: CONFIG_MAGIC_SYSRQ=n
479
480    This should only be needed for debugging.
481
482 .. describe:: CONFIG_DEBUG_KERNEL=y
483
484    This is useful even in a production kernel to enable further configuration
485    options that have security benefits.
486
487 .. describe:: CONFIG_DEBUG_VIRTUAL=y
488
489    Enable sanity checks in virtual to page code.
490
491 .. describe:: CONFIG_STRICT_KERNEL_RWX=y
492
493    Ensure kernel page tables have strict permissions.
494
495 .. describe:: CONFIG_DEBUG_WX=y
496
497    Check and report any dangerous memory mapping permissions, i.e., both
498    writable and executable kernel pages.
499
500 .. describe:: CONFIG_DEBUG_FS=n
501
502    The debugfs virtual file system is only useful for debugging and protecting
503    it would require additional work.
504
505 .. describe:: CONFIG_SLUB_DEBUG_ON=n
506
507    Using the ``slub_debug`` command line parameter provides more fine grained
508    control.
509
510 .. describe:: CONFIG_PANIC_ON_OOPS=y
511               CONFIG_PANIC_TIMEOUT=-1
512
513    Prevent potential further exploitation of a bug by immediately panicking the
514    kernel.
515
516 The following options add additional checks and validation for various
517 commonly targeted kernel structures:
518
519   .. describe:: CONFIG_DEBUG_CREDENTIALS=y
520                 CONFIG_DEBUG_NOTIFIERS=y
521                 CONFIG_DEBUG_LIST=y
522                 CONFIG_DEBUG_SG=y
523   .. describe:: CONFIG_BUG_ON_DATA_CORRUPTION=y
524
525      Note that linux-hardened patches add more places where this configuration
526      option has an impact.
527
528   .. describe:: CONFIG_SCHED_STACK_END_CHECK=y
529   .. describe:: CONFIG_PAGE_POISONING=n
530
531      We choose to poison pages with zeroes and thus prefer using
532      ``init_on_free`` in combination with linux-hardened's
533      ``PAGE_SANITIZE_VERIFY``.
534
535 Security
536 ~~~~~~~~
537
538 .. describe:: CONFIG_SECURITY_DMESG_RESTRICT=y
539
540    Prevent unprivileged users from gathering information from the kernel log
541    buffer via ``dmesg(8)``. Note that this still can be overridden through the
542    ``kernel.dmesg_restrict`` sysctl.
543
544 .. describe:: CONFIG_PAGE_TABLE_ISOLATION=y
545
546    Enable KPTI to prevent Meltdown attacks and, more generally, reduce the
547    number of hardware side channels.
548
549 .. ---
550
551 .. describe:: CONFIG_INTEL_TXT=n
552
553    CLIP OS does not use Intel Trusted Execution Technology.
554
555 .. ---
556
557 .. describe:: CONFIG_HARDENED_USERCOPY=y
558
559    Harden data copies between kernel and user spaces, preventing classes of
560    heap overflow exploits and information leaks.
561
562 .. describe:: CONFIG_HARDENED_USERCOPY_FALLBACK=n
563
564    Use strict whitelisting mode, i.e., do not ``WARN()``.
565
566 .. describe:: CONFIG_FORTIFY_SOURCE=y
567
568    Leverage compiler to detect buffer overflows.
569
570 .. describe:: CONFIG_FORTIFY_SOURCE_STRICT_STRING=n
571
572    This extends ``FORTIFY_SOURCE`` to intra-object overflow checking. It is
573    useful to find bugs but not recommended for a production kernel yet.
574    [linux-hardened]_
575
576 .. describe:: CONFIG_STATIC_USERMODEHELPER=y
577
578    This makes the kernel route all usermode helper calls to a single binary
579    that cannot have its name changed. Without this, the kernel can be tricked
580    into calling an attacker-controlled binary (e.g. to bypass SMAP, cf.
581    `exploitation <https://seclists.org/oss-sec/2016/q4/621>`_ of
582    CVE-2016-8655).
583
584    .. describe:: CONFIG_STATIC_USERMODEHELPER_PATH=""
585
586       Currently, we have no need for usermode helpers therefore we simply
587       disable them. If we ever need some, this path will need to be set to a
588       custom trusted binary in charge of filtering and choosing what real
589       helpers should then be called.
590
591 .. ---
592
593 .. describe:: CONFIG_SECURITY=y
594
595    Enable us to choose different security modules.
596
597 .. describe:: CONFIG_SECURITY_SELINUX=y
598
599    CLIP OS intends to leverage SELinux in its security model.
600
601 .. describe:: CONFIG_SECURITY_SELINUX_BOOTPARAM=n
602
603    We do not need SELinux to be disableable.
604
605 .. describe:: CONFIG_SECURITY_SELINUX_DISABLE=n
606
607    We do not want SELinux to be disabled. In addition, this would prevent LSM
608    structures such as security hooks from being marked as read-only.
609
610 .. describe:: CONFIG_SECURITY_SELINUX_DEVELOP=y
611
612    For now, but will eventually be ``n``.
613
614 .. ---
615
616 .. describe:: CONFIG_LSM="yama"
617
618    SELinux shall be stacked too once CLIP OS uses it.
619
620 .. ---
621
622 .. describe:: CONFIG_SECURITY_YAMA=y
623
624    The Yama LSM currently provides ptrace scope restriction (which might be
625    redundant with CLIP-LSM in the future).
626
627 .. ---
628
629 .. describe:: CONFIG_INTEGRITY=n
630
631    The integrity subsystem provides several components, the security benefits
632    of which are already enforced by CLIP OS (e.g., read-only mounts for all
633    parts of the system containing executable programs).
634
635 .. ---
636
637 .. describe:: CONFIG_SECURITY_PERF_EVENTS_RESTRICT=y
638
639    See documentation about the ``kernel.perf_event_paranoid`` sysctl below.
640    [linux-hardened]_
641
642 .. ---
643
644 .. describe:: CONFIG_SECURITY_TIOCSTI_RESTRICT=y
645
646    This prevents unprivileged users from using the TIOCSTI ioctl to inject
647    commands into other processes that share a tty session. [linux-hardened]_
648
649 .. ---
650
651 .. describe:: CONFIG_GCC_PLUGIN_STACKLEAK=y
652               CONFIG_STACKLEAK_TRACK_MIN_SIZE=100
653               CONFIG_STACKLEAK_METRICS=n
654               CONFIG_STACKLEAK_RUNTIME_DISABLE=n
655
656 ``STACKLEAK`` erases the kernel stack before returning from system calls,
657 leaving it initialized to a poison value. This both reduces the information
658 that kernel stack leak bugs can reveal and the exploitability of uninitialized
659 stack variables. However, it does not cover functions reaching the same stack
660 depth as prior functions during the same system call.
661
662 It used to also block kernel stack depth overflows caused by ``alloca()``, such
663 as Stack Clash attacks. We maintained this functionality for our kernel for a
664 while but eventually `dropped it
665 <https://github.com/clipos/src_external_linux/commit/3e5f9114fc2f70f6d2ae5d10db10869e0564eb03>`_.
666
667 .. describe:: CONFIG_INIT_ON_FREE_DEFAULT_ON=y
668               CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y
669
670    These set ``init_on_free=1`` and ``init_on_alloc=1`` on the kernel command
671    line. See the documentation of these kernel parameters for details.
672
673 .. describe:: CONFIG_PAGE_SANITIZE_VERIFY=y
674               CONFIG_SLAB_SANITIZE_VERIFY=y
675
676    Verify that newly allocated pages and slab allocations are zeroed to detect
677    write-after-free bugs. This works in concert with ``init_on_free`` and is
678    adjusted to not be redundant with ``init_on_alloc``.
679    [linux-hardened]_
680
681 .. ---
682
683 We incorporated most of the *Lockdown* patch series into the CLIP OS kernel,
684 though it may be merged into the mainline kernel in the near future.
685 Basically, *Lockdown* tries to disable many mechanisms that could allow the
686 superuser to eventually run untrusted code in kernel mode (note that a
687 significant portion of them are already disabled in the CLIP OS kernel due to
688 our custom configuration). This is an interesting work for CLIP OS as we want
689 to avoid persistence on a compromised machine even in the case of an
690 already-root attacker. Among the several configuration options brought by
691 *Lockdown*, we enable the following ones:
692
693   .. describe:: CONFIG_LOCK_DOWN_KERNEL=y
694                 CONFIG_LOCK_DOWN_MANDATORY=y
695
696
697 Compilation
698 -----------
699
700 GCC version 7.3.0 or higher is required to fully benefit from retpolines
701 (``-mindirect-branch=thunk-extern``).
702
703
704 Sysctl Security Tuning
705 ----------------------
706
707 Many sysctls are not security-relevant or only play a role if some kernel
708 configuration options are enabled/disabled. In other words, the following is
709 tightly related to the CLIP OS kernel configuration detailed above.
710
711 .. describe:: dev.tty.ldisc_autoload = 0
712
713    See ``CONFIG_LDISC_AUTOLOAD`` above, which serves as a default value for
714    this sysctl.
715
716 .. describe:: kernel.kptr_restrict = 2
717
718    Hide kernel addresses in ``/proc`` and other interfaces, even to privileged
719    users.
720
721 .. describe:: kernel.yama.ptrace_scope = 3
722
723    Enable the strictest ptrace scope restriction provided by the Yama LSM.
724
725 .. describe:: kernel.perf_event_paranoid = 3
726
727    This completely disallows unprivileged access to the ``perf_event_open()``
728    system call. This is actually not needed as we already enable
729    ``CONFIG_SECURITY_PERF_EVENTS_RESTRICT``. [linux-hardened]_
730
731    Note that this requires a patch included in linux-hardened (see `here
732    <https://lwn.net/Articles/696216/>`_ for the reason why it is not upstream).
733    Indeed, on a mainline kernel without such a patch, the above is equivalent
734    to setting this sysctl to ``2``, which would still allow the profiling of
735    user processes.
736
737 .. describe:: kernel.tiocsti_restrict = 1
738
739    This is already forced by the ``CONFIG_SECURITY_TIOCSTI_RESTRICT`` kernel
740    configuration option that we enable. [linux-hardened]_
741
742 The following two sysctls help mitigating TOCTOU vulnerabilities by preventing
743 users from creating symbolic or hard links to files they do not own or have
744 read/write access to:
745
746   .. describe:: fs.protected_symlinks = 1
747                 fs.protected_hardlinks = 1
748
749 In addition, the following other two sysctls impose restrictions on the
750 opening of FIFOs and regular files in order to make similar spoofing attacks
751 harder:
752
753   .. describe:: fs.protected_fifos = 2
754                 fs.protected_regular = 2
755
756 We do not simply disable the BPF Just in Time compiler as CLIP OS plans on
757 using it:
758
759   .. describe:: kernel.unprivileged_bpf_disabled = 1
760
761      Prevent unprivileged users from using BPF.
762
763   .. describe:: net.core.bpf_jit_harden = 2
764
765      Trades off performance but helps mitigate JIT spraying.
766
767 .. describe:: kernel.deny_new_usb = 0
768
769    The management of USB devices is handled at a higher level by CLIP OS.
770    [linux-hardened]_
771
772 .. describe:: kernel.device_sidechannel_restrict = 1
773
774    Restrict device timing side channels. [linux-hardened]_
775
776 .. describe:: fs.suid_dumpable = 0
777
778    Do not create core dumps of setuid executables.  Note that we already
779    disable all core dumps by setting ``CONFIG_COREDUMP=n``.
780
781 .. describe:: kernel.pid_max = 65536
782
783    Increase the space for PID values.
784
785 .. describe:: kernel.modules_disabled = 1
786
787    Disable module loading once systemd has loaded the ones required for the
788    running machine according to a profile (i.e., a predefined and
789    hardware-specific list of modules).
790
791 Pure network sysctls (``net.ipv4.*`` and ``net.ipv6.*``) will be detailed in a
792 separate place.
793
794
795 Command line parameters
796 -----------------------
797
798 We pass the following command line parameters to the kernel:
799
800 .. describe:: extra_latent_entropy
801
802    This parameter provided by a linux-hardened patch (based on the PaX
803    implementation) enables a very simple form of latent entropy extracted
804    during system start-up and added to the entropy obtained with
805    ``GCC_PLUGIN_LATENT_ENTROPY``. [linux-hardened]_
806
807 .. describe:: pti=on
808
809    This force-enables KPTI even on CPUs claiming to be safe from Meltdown.
810
811 .. describe:: spectre_v2=on
812
813    Same reasoning as above but for the Spectre v2 vulnerability. Note that this
814    implies ``spectre_v2_user=on``, which enables the mitigation against user
815    space to user space task attacks (namely IBPB and STIBP when available and
816    relevant).
817
818 .. describe:: spec_store_bypass_disable=seccomp
819
820    Same reasoning as above but for the Spectre v4 vulnerability. Note that this
821    mitigation requires updated microcode for Intel processors.
822
823
824 .. describe:: mds=full,nosmt
825
826    This parameter controls optional mitigations for the Microarchitectural Data
827    Sampling (MDS) class of Intel CPU vulnerabilities. Not specifying this
828    parameter is equivalent to setting ``mds=full``, which leaves SMT enabled
829    and therefore is not a complete mitigation. Note that this mitigation
830    requires an Intel microcode update and also addresses the TSX Asynchronous
831    Abort (TAA) Intel CPU vulnerability on systems that are affected by MDS.
832
833 .. describe:: iommu=force
834
835    Even if we correctly enable the IOMMU in the kernel configuration, the
836    kernel can still decide for various reasons to not initialize it at boot.
837    Therefore, we force it with this parameter. Note that with some Intel
838    chipsets, you may need to add ``intel_iommu=igfx_off`` to allow your GPU to
839    access the physical memory directly without going through the DMA Remapping.
840
841 .. describe:: slub_debug=F
842
843    The ``F`` option adds many sanity checks to various slab operations. Other
844    interesting options that we considered but eventually chose to not use are:
845
846     * The ``P`` option, which enables poisoning on slab cache allocations,
847       disables the ``init_on_free`` and ``SLAB_SANITIZE_VERIFY`` features. As
848       they respectively poison with zeroes on object freeing and check the
849       zeroing on object allocations, we prefer enabling them instead of using
850       ``slub_debug=P``.
851     * The ``Z`` option enables red zoning, i.e., it adds extra areas around
852       slab objects that detect when one is overwritten past its real size.
853       This can help detect overflows but we already rely on ``SLAB_CANARY``
854       provided by linux-hardened. A canary is much better than a simple red
855       zone as it is supposed to be random.
856
857 .. describe:: page_alloc.shuffle=1
858
859    See ``CONFIG_SHUFFLE_PAGE_ALLOCATOR``.
860
861 .. describe:: rng_core.default_quality=512
862
863    Increase trust in the TPM's HWRNG to robustly and fastly initialize Linux's
864    CSPRNG by **crediting** half of the entropy it provides.
865
866 Also, note that:
867
868 * ``slub_nomerge`` is not used as we already set
869   ``CONFIG_SLAB_MERGE_DEFAULT=n`` in the kernel configuration.
870 * ``l1tf``: The built-in PTE Inversion mitigation is sufficient to mitigate
871   the L1TF vulnerability as long as CLIP OS is not used as an hypervisor with
872   untrusted guest VMs. If it were to be someday, ``l1tf=full,force`` should be
873   used to force-enable VMX unconditional cache flushes and force-disable SMT
874   (note that an Intel microcode update is not required for this mitigation to
875   work but improves performance by providing a way to invalidate caches with a
876   finer granularity).
877 * ``tsx=off``: This parameter is already set by default thanks to
878   ``CONFIG_X86_INTEL_TSX_MODE_OFF``. It deactivates the Intel TSX feature on
879   CPUs that support TSX control (i.e. are recent enough or received a microcode
880   update) and that are not already vulnerable to MDS, therefore mitigating the
881   TSX Asynchronous Abort (TAA) Intel CPU vulnerability.
882 * ``tsx_async_abort``: This parameter controls optional mitigations for the TSX
883   Asynchronous Abort (TAA) Intel CPU vulnerability. Due to our use of
884   ``mds=full,nosmt`` in addition to ``CONFIG_X86_INTEL_TSX_MODE_OFF``, CLIP OS
885   is already protected against this vulnerability as long as the CPU microcode
886   has been updated, whether or not the CPU is affected by MDS. For the record,
887   if we wanted to keep TSX activated, we could specify
888   ``tsx_async_abort=full,nosmt``. Not specifying this parameter is equivalent
889   to setting ``tsx_async_abort=full``, which leaves SMT enabled and therefore
890   is not a complete mitigation. Note that this mitigation requires an Intel
891   microcode update and has no effect on systems that are already affected by
892   MDS and enable mitigations against it, nor on systems that disable TSX.
893 * ``kvm.nx_huge_pages``: This parameter allows to control the KVM hypervisor
894   iTLB multihit mitigations. Such mitigations are not needed as long as CLIP OS
895   is not used as an hypervisor with untrusted guest VMs. If it were to be
896   someday, ``kvm.nx_huge_pages=force`` should be used to ensure that guests
897   cannot exploit the iTLB multihit erratum to crash the host.
898 * ``mitigations``: This parameter controls optional mitigations for CPU
899   vulnerabilities in an arch-independent and more coarse-grained way. For now,
900   we keep using arch-specific options for the sake of explicitness. Not setting
901   this parameter equals setting it to ``auto``, which itself does not update
902   anything.
903 * ``init_on_free=1`` is automatically set due to ``INIT_ON_FREE_DEFAULT_ON``. It
904   zero-fills page and slab allocations on free to reduce risks of information
905   leaks and help mitigate a subset of use-after-free vulnerabilities.
906 * ``init_on_alloc=1`` is automatically set due to ``INIT_ON_ALLOC_DEFAULT_ON``.
907   The purpose of this functionality is to eliminate several kinds of
908   *uninitialized heap memory* flaws by zero-filling:
909
910   * all page allocator and slab allocator memory when allocated: this is
911     already guaranteed by our use of ``init_on_free`` in combination with
912     ``PAGE_SANITIZE_VERIFY`` and ``SLAB_SANITIZE_VERIFY`` from linux-hardened,
913     and thus has no effect;
914   * a few more *special* objects when allocated: these are the ones for which
915     we enable ``init_on_alloc`` as they are not covered by the aforementioned
916     combination of ``init_on_free`` and ``SANITIZE_VERIFY`` features.
917
918 .. rubric:: Citations and origin of some items
919
920 .. [linux-hardened]
921    This item is provided by the ``linux-hardened`` patches.
922
923 .. vim: set tw=79 ts=2 sts=2 sw=2 et:
924