Course contentsShow
← Linux
Lesson 1079 of 1,8199. Security Hardening and Mandatory Access ControlFree lesson

Hardening the System Boot Sequence

Ensure the integrity of the entire boot chain from firmware to the OS kernel level.

In this lesson, you will learn how to verify and secure the transition from hardware initialization to kernel execution, creating a verifiable chain of trust.

The Chain of Trust

When you press the power button, your system performs a series of handoffs: from the UEFI/BIOS firmware to the bootloader (like GRUB), and finally to the Linux kernel and the initramfs. If any of these links are compromised—for example, by a malicious bootloader—an attacker can bypass all your Mandatory Access Control policies before the system has even started.

To harden this sequence, we must move from a "trust-on-sight" model to a cryptographic verification model.

Implementing Secure Boot

The primary mechanism for this is UEFI Secure Boot. When enabled, the UEFI firmware checks the digital signature of the bootloader (e.g., shim or grubx64.efi) against keys stored in the hardware’s non-volatile RAM. If the signature doesn’t match, the firmware refuses to execute the code.

Beyond the bootloader, you can extend this trust to the kernel using Unified Kernel Images (UKI). A UKI bundles the kernel, the initramfs, and kernel command-line parameters into a single, signed PE binary. This ensures that the entire environment is validated as a single unit:

# Example of generating a signed UKI using sbctl
sbctl sign -s /boot/EFI/Linux/linux-hardened.efi

Locking the Boot Configuration

Once the boot chain is verified, you must prevent unauthorized modifications to the boot environment. This includes:

  1. Password-protecting the Bootloader: In grub.cfg, use grub2-mkpasswd-pbkdf2 to set a user password, preventing attackers from dropping into a recovery shell or modifying boot arguments (like init=/bin/bash) to bypass root authentication.
  2. Disabling External Boot: Use firmware settings to disable booting from USB or external media to prevent physical tampering.
  3. Kernel Lockdown Mode: Enable kernel lockdown by passing lockdown=integrity or lockdown=confidentiality in your boot arguments. This restricts access to features like /dev/mem or unsigned kernel modules that could be used to subvert the kernel even after a secure boot.

Key Takeaway: Hardening the boot sequence relies on establishing a cryptographically verified chain of trust, ensuring only authorized code executes from the moment the CPU powers on until the kernel assumes full control.