| 1 |
# UEFI Components Security Posture |
| 2 |
The systemd project provides a UEFI boot menu, `systemd-boot`, and a stub that can wrap a Linux kernel in a |
| 3 |
PE binary, adding various features, `systemd-stub`. These components fully support UEFI SecureBoot, and |
| 4 |
this document will describe their security posture and how they comply with industry-standard expectations |
| 5 |
for UEFI SecureBoot workflows. |
| 6 |
|
| 7 |
Note that `systemd-stub` is not the same, or an alternative, to the Linux kernel's own EFI stub. The kernel |
| 8 |
stub's role is that of the fundamental entrypoint to kernel execution from UEFI mode, implementing the |
| 9 |
modern Linux boot protocol. `systemd-stub` on the other hand loads various resources, including the kernel |
| 10 |
image, via the EFI LoadImage/StartImage protocol (although it does support the legacy Linux boot protocol, |
| 11 |
as a fallback for older kernels on x86). The purpose of `systemd-stub` is to provide additional features and |
| 12 |
functionality for `systemd-boot` and `systemd` (in userspace). |
| 13 |
|
| 14 |
## Fundamental Security Design Goals |
| 15 |
The fundamental security design goal for these components is the separation of security policy logic from the |
| 16 |
rest of the functionality. This is achieved by offloading security-critical tasks to the firmware or earlier stages |
| 17 |
of the boot process (in particular `Shim`). |
| 18 |
|
| 19 |
When SecureBoot is enabled, these components are designed to avoid loading, executing, or using |
| 20 |
unauthenticated payloads that could compromise the boot process, with special care taken for anything that |
| 21 |
could affect the system before `ExitBootServices()` has been called. For example, when additional resources |
| 22 |
are loaded, if running with SecureBoot enabled, they will be validated before use. The only exceptions are |
| 23 |
the bootloader's own textual configuration files, and metadata parsed out of kernel images for display purposes |
| 24 |
only. There are no build time or runtime configuration options that can be set to weaken the security model |
| 25 |
of these components when SecureBoot is enabled. |
| 26 |
|
| 27 |
The role of `systemd-boot` is to discover next stage components in the ESP (and XBOOTLDR if present), via |
| 28 |
filesystem enumeration or explicit configuration files, and present a menu to the user to choose the next |
| 29 |
step. This auto discovery mechanism is described in detail in the [BLS (Boot Loader |
| 30 |
Specification)](https://uapi-group.org/specifications/specs/boot_loader_specification/). |
| 31 |
|
| 32 |
The role of `systemd-stub` is to load and measure in the TPM the post-bootloader stages, such as the kernel, |
| 33 |
initrd, and kernel command line, and implement optional features such as augmenting the initrd with |
| 34 |
additional content such as configuration or optional services. [Unified Kernel |
| 35 |
Images](https://uapi-group.org/specifications/specs/unified_kernel_image/) embed `systemd-stub`, a kernel |
| 36 |
and other optional components as sections in a PE signed binary, that can thus be executed in UEFI |
| 37 |
environments. |
| 38 |
|
| 39 |
Since it is embedded in a PE signed binary, `systemd-stub` will temporarily disable the UEFI authentication |
| 40 |
protocol while loading the payload kernel it wraps, in order to avoid redundant duplicate authentication of |
| 41 |
the image, given that the payload kernel was already authenticated and verified as part of the whole image. |
| 42 |
SecureBoot authentication is re-enabled immediately after the kernel image has been loaded. |
| 43 |
|
| 44 |
Various EFI variables, under the vendor UUID `4a67b082-0a4c-41cf-b6c7-440b29bb8c4f`, are set and read by |
| 45 |
these components. This is used to pass metadata and configuration between different stages of the boot process, as |
| 46 |
defined in the [Boot Loader Interface](https://systemd.io/BOOT_LOADER_INTERFACE/). |
| 47 |
|
| 48 |
## Dependencies |
| 49 |
Neither of these components implements cryptographic primitives, cryptographic checks, or drivers. File |
| 50 |
access to the ESP is implemented solely via the appropriate UEFI file protocols. Verification of next stage |
| 51 |
payloads is implementend solely via the appropriate UEFI image load protocols, which means `authenticode` |
| 52 |
signature checks are again done by the firmware or `Shim`. As a consequence, no external security-critical |
| 53 |
libraries (such as OpenSSL or gnu-efi) are linked, embedded, or used. |
| 54 |
|
| 55 |
## Additional Resources |
| 56 |
BLS Type #1 entries allow the user to load two types of additional resources that can affect the system |
| 57 |
before `ExitBootServices()` has been called — kernel command line arguments and DeviceTree blobs — that are |
| 58 |
not validated before use, as they do not carry signatures. For this reason, when SecureBoot is enabled, |
| 59 |
loading these resources is automatically disabled. There is no override for this security mechanism, neither |
| 60 |
at build time nor at runtime. Note that initrds are also not verified in BLS Type #1 configurations, for |
| 61 |
compatibility with how SecureBoot has been traditionally handled on Linux-based OSes, as the kernel will |
| 62 |
only load them after `ExitBootServices()` has been called. |
| 63 |
|
| 64 |
Another mechanism is supported by `systemd-boot` and `systemd-stub` to add additional payloads to the boot |
| 65 |
process: "addons". Addons are PE signed binaries that can carry kernel command line arguments or DeviceTree |
| 66 |
blobs (more payload types might be added in the future). |
| 67 |
In contrast to the user-specified additions in the Type #1 case |
| 68 |
described above, these addons are loaded through the UEFI image loading protocol, and thus are subject to |
| 69 |
signature validation, and will be rejected if not signed or if the signature is invalid, following the |
| 70 |
standard SecureBoot model. They are also measured in the TPM. |
| 71 |
|
| 72 |
`systemd-boot` will also load file system drivers that are stored in the ESP, to allow enhancing the |
| 73 |
firmware's capabilities. These are again PE signed binaries and will be verified using the appropriate |
| 74 |
UEFI protocol. |
| 75 |
|
| 76 |
A random seed will be loaded and passed to the kernel for early-boot entropy if found in the ESP. |
| 77 |
It is mixed with various other sources of entropy available in the UEFI environment, such as the RNG |
| 78 |
protocol, the boot counter and the clock. Moreover, the seed is updated before the kernel is invoked, as |
| 79 |
well as after the kernel is invoked (from userspace), with a new seed derived from the Linux kernel entropy |
| 80 |
pool. |
| 81 |
|
| 82 |
When operating as a virtual machine payload, the loaded payloads can be customized via `SMBIOS Type 11 |
| 83 |
Strings`. Those settings are specified by the hypervisor and trusted. |
| 84 |
They are automatically disabled if running inside a confidential computing VM. |
| 85 |
|
| 86 |
## Certificates Enrollment |
| 87 |
When SecureBoot is supported, but in `setup` mode, `systemd-boot` can enroll user certificates if a set of |
| 88 |
`PK`, `KEK` and `db` certificates is found in the ESP. Afterwards, SecureBoot is enabled and a firmware |
| 89 |
reset is performed. When running on bare metal, the certificates will be shown to the user on the console, |
| 90 |
and manual confirmation is required before proceeding. When running as a virtual machine payload, |
| 91 |
enrollment is fully automated without user interaction, unless disabled via a configuration file in the |
| 92 |
ESP. The configuration file can also be used to disable enrollment completely. |
| 93 |
|
| 94 |
## Compiler Hardening |
| 95 |
The PE binaries are built with `-fstack-protector-strong`, and the stack canary is seeded with random data if |
| 96 |
the UEFI RNG protocol is available. |
| 97 |
|
| 98 |
The binaries also are linked with `-z relro` and ship with native PE relocations, with the conversion from |
| 99 |
ELF performed at build time, instead of containing ELF dynamic relocations, so the image loaded by |
| 100 |
firmware/Shim requires fewer writable pages. |
| 101 |
|
| 102 |
The binaries are linked by default with full LTO support, so no code will be shipped unless it's reachable. |
| 103 |
|
| 104 |
Finally, the binaries ship with the `NX_COMPAT` bit set. |
| 105 |
|
| 106 |
The CI infrastructure also employs fuzz testing on various components, including string functions and the |
| 107 |
BCD parser. |
| 108 |
|
| 109 |
## SBAT |
| 110 |
`systemd-boot` and `systemd-stub` are built with an `SBAT` section by default. There are build options to |
| 111 |
allow customizations of the metadata included in the section, that can be used by downstream distributors. |
| 112 |
The `systemd` project will participate in the coordinated `SBAT` disclosure and metadata revision process as |
| 113 |
deemed necessary, in coordination with the Shim Review group. |
| 114 |
|
| 115 |
The upstream project name used to be unified (`systemd`) for both components, but since version 255 has |
| 116 |
been split into separate `systemd-boot` and `systemd-stub` project names, so that each component can be |
| 117 |
revisioned independently. Most of the code tends to be shared between these two components, but the |
| 118 |
overlap is not complete, so a future vulnerability may affect only one of the components. |
| 119 |
|
| 120 |
## Known Vulnerabilities |
| 121 |
There is currently one known (and fixed) security vulnerability affecting `systemd-boot` on arm64 and |
| 122 |
riscv64 systems. For details of the affected and fixed versions, please see the [published security |
| 123 |
advisory.](https://github.com/systemd/systemd/security/advisories/GHSA-6m6p-rjcq-334c) |