SYSTEMD-STUB(7) | systemd-stub | SYSTEMD-STUB(7) |
NAME¶
systemd-stub, sd-stub, linuxx64.efi.stub, linuxia32.efi.stub, linuxaa64.efi.stub - A simple UEFI kernel boot stub
SYNOPSIS¶
DESCRIPTION¶
systemd-stub (stored in per-architecture files linuxx64.efi.stub, linuxia32.efi.stub, linuxaa64.efi.stub on disk) is a simple UEFI boot stub. An UEFI boot stub is attached to a Linux kernel binary image, and is a piece of code that runs in the UEFI firmware environment before transitioning into the Linux kernel environment. The UEFI boot stub ensures a Linux kernel is executable as regular UEFI binary, and is able to do various preparations before switching the system into the Linux world.
The UEFI boot stub looks for various resources for the kernel invocation inside the UEFI PE binary itself. This allows combining various resources inside a single PE binary image (a "Unified Kernel Image" or "UKI" for short), which may then be signed via UEFI SecureBoot as a whole, covering all individual resources at once. Specifically it may include the following PE sections:
In a basic UKI, the sections listed above appear at most once, with the exception of ".dtbauto" and ".hwids" sections. In a multi-profile UKI, multiple sets of these sections are present in a single file and form "profiles", one of which can be selected at boot. For this, the PE section ".profile" is defined to be used as the separator between sets of sections. The ".profile" section itself may contain meta-information about the section, and follows a similar structure as the contents of the ".osrel" section. For further details about multi-profile UKIs, see below.
If UEFI SecureBoot is enabled and the ".cmdline" section is present in the executed image, any attempts to override the kernel command line by passing one as invocation parameters to the EFI binary are ignored. Thus, in order to allow overriding the kernel command line, either disable UEFI SecureBoot, or don't include a kernel command line PE section in the kernel image file. If a command line is accepted via EFI invocation parameters to the EFI binary it is measured into TPM PCR 12 (if a TPM is present).
If a DeviceTree is embedded in the ".dtb" section, it replaces an existing DeviceTree in the corresponding EFI configuration table. systemd-stub will ask the firmware via the "EFI_DT_FIXUP_PROTOCOL" for hardware specific fixups to the DeviceTree.
The contents of 11 of these 12 sections are measured into TPM PCR 11. It is otherwise not used and thus the result can be pre-calculated without too much effort. The ".pcrsig" section is not included in this PCR measurement, since it is supposed to contain signatures for the output of the measurement operation, and thus cannot also be input to it. If an UKI contains multiple profiles, only the PE sections of the selected profile (and those of the base profile, except if overridden) are measured.
If non-zero, the selected numeric profile is measured into PCR 12.
When ".pcrsig" and/or ".pcrpkey" sections are present in a unified kernel image their contents are passed to the booted kernel in an synthetic initrd cpio archive that places them in the /.extra/tpm2-pcr-signature.json and /.extra/tpm2-pcr-public-key.pem files. Typically, a tmpfiles.d(5) line then ensures they are copied into /run/systemd/tpm2-pcr-signature.json and /run/systemd/tpm2-pcr-public-key.pem where they remain accessible even after the system transitions out of the initrd environment into the host file system. Tools such systemd-cryptsetup@.service(8), systemd-cryptenroll(1) and systemd-creds(1) will automatically use files present under these paths to unlock protected resources (encrypted storage or credentials) or bind encryption to booted kernels.
For further details about the UKI concept, see the UKI specification[3].
COMPANION FILES¶
The systemd-stub UEFI boot stub automatically collects three types of auxiliary companion files optionally placed in drop-in directories on the same partition as the EFI binary, dynamically generates cpio initrd archives from them, and passes them to the kernel. Specifically:
In case Secure Boot is enabled, these files will be validated using keys in UEFI DB, Shim's DB or Shim's MOK, and only loaded if the check passes. Additionally, if both the addon and the UKI contain a ".uname" section, the addon will be rejected if they do not match exactly. It is recommended to always add a ".sbat" section to all signed addons, so that they may be revoked with a SBAT policy update, without requiring blocklisting via DBX/MOKX. The ukify(1) tool will add a SBAT policy by default if none is passed when building addons. For more information on SBAT see Shim documentation[2].
Addon files are sorted, loaded, and measured into TPM PCR 12 (if a TPM is present) and appended to the kernel command line. UKI command line options are listed first, then options from addons in /loader/addons/*.addon.efi, and finally UKI-specific addons. Device tree blobs are loaded and measured following the same algorithm. Microcode addons are passed to the kernel in inverse order (UKI specific addons, global addons, UKI embedded section). This is because the microcode update driver stops on the first matching filename. Addons are always loaded in the same order based on the filename, so that, given the same set of addons, the same set of measurements can be expected in PCR12. However, note that the filename is not protected by the PE signature, and as such an attacker with write access to the ESP could potentially rename these files to change the order in which they are loaded, in a way that could alter the functionality of the kernel, as some options might be order-dependent. If you sign such addons, you should pay attention to the PCR12 values and make use of an attestation service so that improper use of your signed addons can be detected and dealt with using one of the aforementioned revocation mechanisms.
These mechanisms may be used to parameterize and extend trusted (i.e. signed), immutable initrd images in a reasonably safe way: all data they contain is measured into TPM PCRs. On access they should be further validated: in case of the credentials case by encrypting/authenticating them via TPM, as exposed by systemd-creds encrypt -T (see systemd-creds(1) for details); in case of the system extension images by using signed Verity images.
MULTI-PROFILE UKIS¶
In many contexts it is useful to allow invocation of a single UKI in multiple different modes (or "profiles") without compromising the cryptographic integrity, measurements and so on of the boot process. For example, a single UKI might provide three distinct profiles: a regular boot one, one that invokes a "factory reset" operation, and one that boots into a storage target mode (as in systemd-storagetm.service(8)). Each profile would then use the same ".linux" and ".initrd" sections, but would have a separate ".cmdline" section. For example the latter two profiles would extend the regular kernel command line with "systemd.unit=factory-reset.target" or "rd.systemd.unit=storagetm.target".
A single UKI may support multiple profiles by means of the special ".profile" PE section. This section acts as separator between the PE sections of the individual profiles. ".profile" PE sections hence may appear multiple times in a single UKI, and the other PE sections listed above may appear multiple times too, if ".profile" are used, but only once before the first ".profile" section, once between each subsequent pair, and once after the last appearance of ".profile". The sections listed before the first ".profile" are considered the "base" profile of the UKI. Each ".profile" section then introduces a new profile, which are numbered starting from zero. The PE sections following each ".profile" are specific to that profile. When booting into a specific profile the base section's profiles are used in combination with the specific profile's sections: if the same section is defined in both, the per-profile section overrides the base profile's version, otherwise the per-profile sections is used together with the base profile sections.
A UKI that contains no ".profile" is consider equivalent to one that just contains a single ".profile", as having only a single profile @0.
Here's a simple example for a multi-profile UKI's sections, inspired by the setup suggested above:
Table 1. Multi-Profile UKI Example
Section | Profile |
".linux" | Base profile |
".osrel" | |
".cmdline" | |
".initrd" | |
".profile" | Profile @0 |
".profile" | Profile @1 |
".cmdline" | |
".profile" | Profile @2 |
".cmdline" |
The section list above would define three profiles. The first four
sections make up the base profile. A
".profile" section then introduces profile @0. It doesn't override
any sections (or add any) from the base section, hence it is immediately
followed by another ".profile" section that then introduces
section @1. This profile overrides the kernel command line. Finally, the
last two sections define section @2, again overriding the command line.
(Note that in this example the first ".cmdline" could also moved
behind the first ".profile" with equivalent effect. To keep things
nicely extensible, it's probably a good idea to keep the generic command
line in the base section instead of profile 0, in case later added profiles
might want to reuse it.)
The profile to boot may be controlled via the UKI's own command line: if the first argument starts with "@", followed by a positive integer number in decimal, it selects the profile to boot into. If the first argument is not specified like that, the UKI will automatically boot into profile 0.
A ".profile" section may contain meta-information about the profile. It follows a similar format as ".osrel" (i.e. an environment-variable-assignment-block-like list of newline separated strings). Currently two fields are defined: "ID=" is supposed to carry a short identifying string that identifies the profile (e.g. "ID=factory-reset"). "TITLE=" should contain a human readable string that may appear in the boot menu entry for this profile (e.g. "TITLE='Factory Reset this Device'").
TPM PCR NOTES¶
Note that when a unified kernel using systemd-stub is invoked the firmware will measure it as a whole to TPM PCR 4, covering all embedded resources, such as the stub code itself, the core kernel, the embedded initrd and kernel command line (see above for a full list), including all UKI profiles.
Also note that the Linux kernel will measure all initrds it receives into TPM PCR 9. This means every type of initrd (of the selected UKI profile) will possibly be measured two or three times: the initrds embedded in the kernel image will be measured to PCR 4, PCR 9 and PCR 11; the initrd synthesized from credentials (and the one synthesized from configuration extensions) will be measured to both PCR 9 and PCR 12; the initrd synthesized from system extensions will be measured to both PCR 4 and PCR 9. Let's summarize the OS resources and the PCRs they are measured to:
Table 2. OS Resource PCR Summary
OS Resource | Measurement PCR |
systemd-stub code (the entry point of the unified PE binary) | 4 |
Core kernel code (embedded in unified PE binary) | 4 + 11 |
OS release information (embedded in the unified PE binary) | 4 + 11 |
Main initrd (embedded in unified PE binary) | 4 + 9 + 11 |
Microcode initrd (embedded in unified PE binary) | 4 + 9 + 11 |
Default kernel command line (embedded in unified PE binary) | 4 + 11 |
Overridden kernel command line | 12 |
Boot splash (embedded in the unified PE binary) | 4 + 11 |
TPM2 PCR signature JSON (embedded in unified PE binary, synthesized into initrd) | 4 + 9 |
TPM2 PCR PEM public key (embedded in unified PE binary, synthesized into initrd) | 4 + 9 + 11 |
Credentials (synthesized initrd from companion files) | 9 + 12 |
System Extensions (synthesized initrd from companion files) | 9 + 13 |
Configuration Extensions (synthesized initrd from companion files) | 9 + 12 |
Selected profile unless zero | 12 |
EFI VARIABLES¶
The following EFI variables are defined, set and read by
systemd-stub, under the vendor UUID
"4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", for communication between
the boot stub and the OS:
LoaderDevicePartUUID
Added in version 224.
LoaderFirmwareInfo, LoaderFirmwareType
Added in version 250.
LoaderImageIdentifier
Added in version 237.
StubDevicePartUUID, StubImageIdentifier
Added in version 257.
StubInfo
Added in version 250.
StubPcrKernelImage
Added in version 252.
StubPcrKernelParameters
Added in version 252.
StubPcrInitRDSysExts
Added in version 252.
StubPcrInitRDConfExts
Added in version 255.
StubProfile
Added in version 257.
Note that some of the variables above may also be set by the boot loader. The stub will only set them if they aren't set already. Some of these variables are defined by the Boot Loader Interface[5].
INITRD RESOURCES¶
The following resources are passed as initrd cpio archives to the booted kernel, and thus make up the initial file system hierarchy in the initrd execution environment:
/
Added in version 252.
/.extra/credentials/*.cred
Added in version 252.
/.extra/global_credentials/*.cred
Added in version 252.
/.extra/sysext/*.sysext.raw
Added in version 252.
/.extra/confext/*.confext.raw
Added in version 255.
/.extra/tpm2-pcr-signature.json
Added in version 252.
/.extra/tpm2-pcr-public-key.pem
Added in version 252.
/.extra/profile, /.extra/os-release
Added in version 257.
Note that all these files are located in the "tmpfs" file system the kernel sets up for the initrd file hierarchy and are thus lost when the system transitions from the initrd execution environment into the host file system. If these resources shall be kept around over this transition they need to be copied to a place that survives the transition first, for example via a suitable tmpfiles.d(5) line. By default, this is done for the TPM2 PCR signature and public key files.
SMBIOS TYPE 11 STRINGS¶
systemd-stub can be configured using SMBIOS Type 11 strings. Applicable strings consist of a name, followed by "=", followed by the value. Unless systemd-stub detects it is running inside a confidential computing environment, systemd-stub will search the table for a string with a specific name, and if found, use its value. The following strings are read:
io.systemd.stub.kernel-cmdline-extra
Added in version 254.
ASSEMBLING KERNEL IMAGES¶
In order to assemble a bootable Unified Kernel Image from various components as described above, use ukify(1).
SEE ALSO¶
systemd-boot(7), systemd.exec(5), systemd-creds(1), systemd-sysext(8), Boot Loader Specification[6], Boot Loader Interface[5], ukify(1), systemd-measure(1), TPM2 PCR Measurements Made by systemd[7]
NOTES¶
- 1.
- specification
- 2.
- SBAT
- 3.
- UKI specification
- 4.
- Automatic Boot Assessment
- 5.
- Boot Loader Interface
- 6.
- Boot Loader Specification
- 7.
- TPM2 PCR Measurements Made by systemd
systemd 257.1 |