Skip to content

efi: check what install copies to the ESP, and what updates apply - #1192

Draft
LorbusChris wants to merge 8 commits into
coreos:mainfrom
LorbusChris:esp-copy-checks
Draft

LorbusChris wants to merge 8 commits into
coreos:mainfrom
LorbusChris:esp-copy-checks

Conversation

@LorbusChris

@LorbusChris LorbusChris commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1191, which is stacked on #1190; only the last two commits are new here. They came out of review of those two PRs, and are split off so that those can be reviewed on their own.

install copies the requested bootloader's component, and those of no bootloader such as shim's, one over another to the ESP's FAT file system. FAT ignores case and trailing dots and cannot hold symlinks, some names, or files over 4 GiB, while the file tree that bootupd records, and the updates based on it, compare names exactly. So payloads that look fine in a directory can install a shim that cannot load its bootloader, fail the copy halfway after writing to the ESP, or leave a recorded tree that a later update applies wrongly.

  1. efi: check that the installed shim can load the bootloader. Before touching the ESP, install checks that:

    • the one shim is copied for the requested bootloader (in usr/lib/efi, from a shim component, as updates require), directly into a vendor directory such as EFI/fedora, whose name the firmware entry uses;
    • the bootloader lands at the exact path shim loads, EFI/<vendor>/grub<arch>.efi;
    • nothing it copies is a symlink or special file, a name FAT refuses or may give another entry as its short name (such as RELEAS~1), a file over 4 GiB, or bootupd's temporary prefix in any case, and entries that would share a name on the ESP are copies of one directory or file at the same path;
    • the file tree it records holds exactly the files it copies.

    It reads that tree within the source root, before touching the ESP, and registers the vendor of the shim it checked with the firmware. It also refuses an ESP mounted with nonumtail, where a long name gets the short name made of its first characters: CentOS's aarch64 shimaa64-centos.efi could take SHIMAA64.EFI, the name of the shim beside it. backend list-bootloaders runs the same checks for each bootloader it lists.

  2. efi: refuse updates that name one ESP entry two ways. apply_diff stages each directory below EFI under its exact name, so an installed EFI/fedora and an update's EFI/FEDORA make it swap the one FAT directory twice, undoing the update while reporting success. Before writing to the ESP, bootupctl update and adoption now refuse such payloads, and trees that name an entry two ways, also through a short name FAT makes up, or as both a file and a directory. Like install, they refuse an ESP mounted with nonumtail. Nor can an update replace a directory on the ESP with a file, which failed while staging after files directly below EFI were already removed; apply_diff checks the ESP itself, since the file trees miss directories that earlier updates emptied. The file tree refuses different files at one path and the temporary prefix in any case, and apply_diff refuses to reuse a directory whose name differs from its staging name only in case.

Real payloads are unaffected: CentOS Stream 9 and 10, and Fedora 44 with GRUB and systemd-boot, install and list as before.

Testing

  • Unit tests cover each refusal (each fails without its check), the update guard, the file tree and apply_diff. install also ran unprivileged onto a real vfat ESP mounted with default options, and list-bootloaders and install up to the ESP step accept CentOS Stream 10's aarch64 payload (emulated). fmt, test and clippy pass at each commit; s390x and ppc64le build as on main (emulated).
  • Compared with 0.4.0 on payloads made from real images, up to the ESP step:
Payload Install 0.4.0 This series
Fedora 44 with GRUB and systemd-boot, shim moved into systemd-boot's component --bootloader grub or systemd proceeds; GRUB would be installed without shim, or systemd-boot with a shim that no update accepts refused before
Fedora 44 with GRUB and systemd-boot, GRUB moved to EFI/redhat --bootloader grub proceeds; shim could not load GRUB refused before
Fedora 44 with GRUB and systemd-boot, shim and GRUB moved below EFI/extra/ --bootloader grub or systemd proceeds; shim would not be where bootupd registers it refused before
Fedora 44 with GRUB and systemd-boot, a copy of the GRUB binary added to the shim component --bootloader systemd proceeds; the copy would replace systemd-boot refused before
CentOS Stream 10 with its legacy update directory replaced by a symlink --bootloader grub proceeds; the copy to the ESP would fail refused before
Fedora 44 with GRUB and systemd-boot, the shim component with a file whose name the ESP merges with another's: EFI/fedora/SHIMX64.EFI, EFI/fedora/grubx64.efi., or a copy of GRUB as EFI/fedora/GRUBX64.EFI --bootloader grub or systemd proceeds; the later copy would replace the checked one, or bootupd would track one file under two names refused before
Fedora 44 with GRUB and systemd-boot, a symlink added to the shim component, or a component whose vendor directory links to itself --bootloader grub or systemd proceeds; copying it to the ESP would fail refused before
Fedora 44 with GRUB and systemd-boot, an extra component with a file EFI/FEDORA --bootloader grub or systemd proceeds; copying it over the EFI/fedora directory would fail refused before
Fedora 44 with GRUB and systemd-boot, a .btmp.leftover file in usr/lib/efi --bootloader grub or systemd proceeds; recording the file tree would fail after the copy refused before
Fedora 44 with GRUB and systemd-boot, the shim component with EFI/fedora/help:debug.txt or EFI/fedora/notes.txt (a trailing space), names FAT cannot hold --bootloader grub or systemd proceeds; the copy would fail halfway refused before
Fedora 44 with GRUB and systemd-boot, the shim component with EFI/.BTMP.fedora, or an extra component with EFI/fedora/RELEAS~1 --bootloader grub or systemd proceeds; a later update could reuse the first as its staging directory, and FAT may already use the second as a short name refused before
CentOS Stream 10 with tools/1/EFI/helper.efi in its legacy update directory --bootloader grub proceeds; bootupd would record the file as EFI/helper.efi refused before
Fedora 44 with GRUB and systemd-boot, a stray usr/lib/efi/notes.txt --bootloader grub or systemd proceeds; bootupd would record a file it did not copy refused before
Fedora 44 with GRUB and systemd-boot, GRUB in EFI/FEDORA beside shim's EFI/fedora --bootloader grub proceeds; bootupd would record one directory under two names refused before
Fedora 44 with GRUB and systemd-boot, GRUB only as EFI/fedora/GRUBX64.EFI, or a systemd-boot directory inside the GRUB component --bootloader grub proceeds; updates would not protect, or bootupd would not record, those files refused before

Also unchanged, proceeding with both: --bootloader systemd on the Fedora 44 payloads where only GRUB is moved, renamed or given extra files, and --bootloader grub with an identical copy of the GRUB binary at the same path in the shim component.

Assisted-by: LLM

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
Pre-merge checks: Passed 1

Check name Status Explanation
Commit Message Convention Passed All 8 non-merge commits in the PR range (merge-base bb0362f, main..HEAD) follow the required 'subsystem: lowercase description' format. No merge commits are present. I deepened the shallow clone to re…
Full details: Commit Message Convention

Explanation

All 8 non-merge commits in the PR range (merge-base bb0362f, main..HEAD) follow the required 'subsystem: lowercase description' format. No merge commits are present. I deepened the shallow clone to recover the full range, since the checkout initially held only the head commit. Commit subjects checked (hash, subject): - 06d5fa8 efi: fail on payload directories that cannot be read: conforms. - ea5067e install: fix the bootloader choice for images without usr/lib/efi: conforms. - 9fdf5eb efi: refuse a bootloader the update payload lacks, or has twice: conforms. - a2bd4ae efi: check for shim before touching the ESP: conforms. - a0f09a9 install: check the payloads before installing any component: conforms. - 10953db cli: add \backend list-bootloaders` to query an image's bootloaders: conforms. - 21301d5 efi: check that the installed shim can load the bootloader: conforms. - ba40eaa efi: refuse updates that name one ESP entry two ways`: conforms. Each subject has a lowercase first word after the colon, an imperative verb (fail, fix, refuse, check, add), and no trailing period. The subsystems (efi, install, cli) are component names, which the check accepts. The PR title was not evaluated, since the check covers commit messages only.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@openshift-ci

openshift-ci Bot commented Nov 29, 2026

Copy link
Copy Markdown

Hi @LorbusChris. Thanks for your PR.

I'm waiting for a coreos member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Listing the components in usr/lib/efi skips directories it cannot read,
so the components in them look absent. install and update then report a
needed component as missing, hiding the read error, and
generate-update-metadata silently leaves it out. Likewise, a usr/lib/efi
whose existence cannot be checked, or that is a symbolic link leading
nowhere, counts as missing, so all three fall back to the legacy update
directory.

Fail with the read error, or one naming the dangling link, instead.
Only a missing usr/lib/efi still means there are no components.

Assisted-by: LLM
Without --bootloader, a default bootloader in the metadata, or a BIOS
component among the targets, install picks the only bootloader whose
component the EFI update metadata names. Since bootupd 0.4.0 (e4e9a49),
the metadata of an image without usr/lib/efi names packages such as
grub2-efi-x64 instead. install then finds no bootloader and fails with
"Multiple bootloaders found as install candidates". This breaks
installing such images, CentOS Stream 10 for instance, once 0.4.0
generates their metadata. It hits aarch64, and x86_64 when only the EFI
component is installed: with --component EFI, or with --auto on an
EFI-booted host, as `bootc install` does.

Pick from the bootloaders the payload carries, since that is what
install copies. With usr/lib/efi, these are the bootloaders with their
own component there holding the bootloader binary. Without it, it is
GRUB if the legacy update directory holds its binary. If the metadata
names bootloaders, keep only those. Metadata not regenerated after
adding a bootloader then still gives the same choice, and metadata not
regenerated after removing one no longer fails. With several
candidates, the error names them and says to pass --bootloader or set a
default in the image. With none, it says why. An unreadable payload
directory fails the choice instead of hiding a bootloader.

Move the choice into its own function so it can be tested with
install's options.

The error suggests set-default-bootloader, so make that work for GRUB
on images without BIOS.json, such as x86_64 images without
grub2-install. It now skips components without update metadata instead
of failing on them. It still needs EFI metadata, since install only
reads the EFI default.

CI missed this because its CentOS Stream images kept the metadata the
base image's bootupd wrote. On CentOS Stream 10, regenerate it with the
bootupd under test, so the aarch64 install exercises the choice. On
CentOS Stream 9, keep the old metadata to keep covering images that
update bootupd without regenerating it, and fail the build once the
base image ships the new format.

Assisted-by: LLM
Since 0.4.0 (9a030b3), install refuses a bootloader whose component is
missing from usr/lib/efi before touching the ESP. For an image without
usr/lib/efi, though, it lets any bootloader pass. It then copies the
whole legacy update directory, which only carries GRUB. So `install
--bootloader systemd` on such an image, CentOS Stream 10 for instance,
installs GRUB, reports success, and saves its state as for
systemd-boot.

Before touching the ESP, refuse a bootloader the payload does not
carry, as found by the previous commit. This is stricter than the check
from 9a030b3: a component directory without the bootloader binary does
not count, and an empty usr/lib/efi next to the legacy update directory
is refused up front instead of after mounting the ESP. Also refuse a
bootloader whose component has several versions holding the binary,
since install would copy them over one another in no particular order
and record either in its state. An empty version directory left behind
by an upgrade does not count. Updates and adoption keep their checks.

Assisted-by: LLM
After copying the EFI payload to the ESP, install takes the EFI vendor
directory from the shim binary in the payload, and fails unless there
is exactly one. A payload with no shim, or two, therefore fails only
after writing to the ESP, leaving the copied files there without saved
state.

Check for exactly one shim before touching the ESP, next to the
bootloader check. Unlike the vendor lookups after the copy, which still
skip unreadable directories, this check fails on them, since one could
hide a shim.

Assisted-by: LLM
install installs the selected components one after the other, BIOS
before EFI. The EFI component checks its update payload before touching
the ESP, but by then BIOS has already run grub2-install on the target
device. So a payload the EFI component refuses, such as one whose grub2
component lacks the GRUB binary, fails the install after that write,
without saving state for it. The previous commits make the EFI component
refuse more payloads, so this would now happen more often.

Decide which components to install first, with the same rules as
before, and check each one's payload before installing any. A new
Component::check_payload() runs the EFI component's checks. The BIOS
component's looks at what it runs from the running system, not from the
source root: grub2-install has to start, which asking for its version
shows, and the GRUB modules have to include the modinfo.sh it reads
first. Without them it fails after EFI, when installed in the other
order, has written to the ESP.

Assisted-by: LLM
Tools that install an image's bootloader with `backend install`, such as
bootc, need to know beforehand which bootloaders the image's update
payload offers, for instance to decide whether to ask for systemd-boot.
bootupd cannot tell them: `bootupctl status` describes the booted
system, and in a container it only names the BIOS and EFI components.
So such a tool has to inspect the payload itself and mirror bootupd's
rules, as proposed for bootc in
bootc-dev/bootc#2512.

Add `backend list-bootloaders`. It prints the bootloaders `backend
install --bootloader` can install from the update payload in
--src-root, using the names --bootloader accepts, and the EFI
component's default bootloader if one was set with
`set-default-bootloader`. Pass --json for JSON. Like `install`, it
takes --component or --auto and selects components the same way.

Each component reports what it can install through a new
Component::payload_bootloaders(). EFI offers the bootloaders its
payload carries that pass the checks `install` runs before touching the
ESP. BIOS offers GRUB if grub2-install and its modules are on the
running system, since `install` runs them from there. A bootloader is
listed if some selected component can install it and every selected
component that has update metadata and supports it can, as `install`
requires. Warnings say why a component cannot install a bootloader or
has no metadata. An unreadable source root or payload is an error. Pass
--component EFI to leave BIOS out.

While here, --auto, for `install` too, now returns an error instead of
panicking when it cannot check for /sys/firmware/efi. CI checks the
output on the CentOS Stream and Fedora test images.

See bootc-dev/bootc#2512 (comment)

Assisted-by: LLM
The shim check before the ESP looked for exactly one shim anywhere in
the update payload. `install` then copies only the requested
bootloader's component and those that belong to no bootloader, such as
shim's. A shim found only in another bootloader's component, such as
systemd-boot's, was therefore not installed: without firmware updates,
the install succeeded with no shim on the ESP, and with them, it failed
after writing to the ESP. Updates also require shim in a 'shim'
component, so a shim elsewhere made every later update fail.

Shim also loads the bootloader as grub<arch>.efi from its own
directory, so a payload with EFI/fedora/shimx64.efi and
EFI/redhat/grubx64.efi installed a shim that cannot load it. bootupd
registers EFI/<vendor>/shimx64.efi with the firmware, naming the
vendor after shim's directory, so a shim deeper below EFI, such as
EFI/extra/fedora/shimx64.efi, failed the install after writing to the
ESP when it updated the firmware's boot entries.

`install` copies the components one over another to the ESP's FAT file
system, which ignores case and trailing dots and cannot hold symbolic
links or names such as help:debug.txt, while the file tree bootupd
records, and the updates based on it, compare names exactly. So another
component's EFI/fedora/GRUBX64.EFI replaced the bootloader that was
checked; a symbolic link, a name FAT refuses, or a file where another
component has a directory failed the copy halfway; and names that
differ only in case left the recorded tree out of step with the ESP.
The tree also recorded files outside the components' EFI directories,
which `install` does not copy, left out directories named like another
bootloader's component, which it does, and recorded a file of the legacy
update directory whose path has EFI as its third part under another
path. Without usr/lib/efi,
`install` copies the legacy update directory with `cp -r`, which
copies it as a link if it is one. `install` also read the file tree it
records only after copying, so a payload it cannot record failed after
writing to the ESP.

Check all of this before touching the ESP, using the same list of
components that `install` copies: entries that would share a name on
the ESP must be copies of one directory or file at the same path, the
bootloader and shim must have their exact names, and the recorded tree
must hold exactly the files `install` copies. Names that FAT may give
another entry as its short name, such as RELEAS~1, also with trailing
dots, names directly below EFI too long to stage an update under
bootupd's temporary prefix, files over FAT's 4 GiB limit, and that
prefix in any case are refused too. So is an ESP mounted with
nonumtail, where FAT gives a long name the short name made of its first
characters: CentOS's shimaa64-centos.efi could take SHIMAA64.EFI, the
name of the shim beside it. Copies of one file are compared a block at
a time. The firmware's boot entry
uses the vendor directory of the shim that the check found, rather than
one looked up again after copying. The payload is read
within the source root, as before this series, so a usr/lib/efi that
links out of it fails before anything reads there. Shim and the
bootloader may still come from
different components, as with Fedora's shim and grub2 packages. A
payload directory that cannot be read while checking is an error, kept
apart from the reasons why a bootloader cannot be installed. The check
keeps requiring exactly one shim in the whole payload, since the
vendor lookups after the copy still search all of it.

`backend list-bootloaders` runs the same checks for each bootloader it
lists, leaving out, with a warning, those that `install` would refuse,
and failing where `install` cannot read the payload.

Assisted-by: LLM
The ESP's FAT file system ignores case and trailing dots, but the file
tree that bootupd records, and `apply_diff`, which applies updates and
adoptions, compare names exactly. `apply_diff` stages each directory
directly below EFI under its name. When the installed files and an
update name one such directory both EFI/fedora and EFI/FEDORA, it
stages the one FAT directory twice, under one temporary name on FAT,
and swaps it in twice: the second swap undoes the first, leaving the
old contents in place, and the update still reports success. An entry
that one tree names two ways is tracked as two files: the copy writes
one over the other, and an update that drops one name removes the
file, as older versions could record when components shipped copies
of one file. An entry that is both a file and a directory cannot be
staged at all. Adoption applies its payload the same way.

Staging also copies, writes and removes entries by names that FAT can
resolve to another entry: an update that adds RELEAS~1 beside an
unchanged release-notes can succeed with release-notes gone. On an ESP
mounted with nonumtail, which gives long names short names without a
number, real payloads can collide that way too. A file where the ESP
has a directory, which the file trees miss when an earlier update
emptied it, fails while staging, after files directly below EFI have
already been removed from the ESP.

`install` already refuses such payloads, or cannot produce them, but
`bootupctl update` and adoption do not run its checks. Refuse such an
update, or adoption payload, before writing to the ESP, and, as
`install` does, an ESP mounted with nonumtail; `apply_diff` looks for
directories in the way on the ESP itself. Further below
EFI's directories, an update may still name an entry another way than
the installed files: `apply_diff` removes the old name before it
writes the new one, in the same staging copy.

The file tree also kept one of several different files that land on
one path, in no particular order, and let bootupd's temporary prefix
through in another case. It now refuses both, and keeps the first of
identical copies in sorted order. `apply_diff` also reused a directory
on the ESP whose name differs from its temporary one only in case, such
as .BTMP.fedora, which its cleanup does not remove, as the staging
copy. It now refuses to, and leaves alone other entries with such
names, which are not in its way.

Assisted-by: LLM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant