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:
- Password-protecting the Bootloader: In
grub.cfg, usegrub2-mkpasswd-pbkdf2to set a user password, preventing attackers from dropping into a recovery shell or modifying boot arguments (likeinit=/bin/bash) to bypass root authentication. - Disabling External Boot: Use firmware settings to disable booting from USB or external media to prevent physical tampering.
- Kernel Lockdown Mode: Enable kernel lockdown by passing
lockdown=integrityorlockdown=confidentialityin your boot arguments. This restricts access to features like/dev/memor 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.