Repository navigation
efi: check what install copies to the ESP, and what updates apply - #1192
LorbusChris wants to merge 8 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: truePre-merge checks:
|
| Check name | Status | Explanation |
|---|---|---|
| Commit Message Convention | 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. - ea5067einstall: fix the bootloader choice for images without usr/lib/efi: conforms. - 9fdf5ebefi: refuse a bootloader the update payload lacks, or has twice: conforms. - a2bd4aeefi: check for shim before touching the ESP: conforms. - a0f09a9install: check the payloads before installing any component: conforms. - 10953dbcli: add \backend list-bootloaders` to query an image's bootloaders: conforms. - 21301d5efi: check that the installed shim can load the bootloader: conforms. - ba40eaaefi: 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
|
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 Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
8d423eb to
06e6dad
Compare
cf46a56 to
ba40eaa
Compare
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
ba40eaa to
ce2d3d2
Compare
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
ce2d3d2 to
98f360a
Compare
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.
installcopies 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.efi: check that the installed shim can load the bootloader. Before touching the ESP,
installchecks that:usr/lib/efi, from ashimcomponent, as updates require), directly into a vendor directory such asEFI/fedora, whose name the firmware entry uses;EFI/<vendor>/grub<arch>.efi;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;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 aarch64shimaa64-centos.eficould takeSHIMAA64.EFI, the name of the shim beside it.backend list-bootloadersruns the same checks for each bootloader it lists.efi: refuse updates that name one ESP entry two ways.
apply_diffstages each directory belowEFIunder its exact name, so an installedEFI/fedoraand an update'sEFI/FEDORAmake it swap the one FAT directory twice, undoing the update while reporting success. Before writing to the ESP,bootupctl updateand 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. Likeinstall, they refuse an ESP mounted withnonumtail. Nor can an update replace a directory on the ESP with a file, which failed while staging after files directly belowEFIwere already removed;apply_diffchecks 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, andapply_diffrefuses 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
apply_diff.installalso ran unprivileged onto a real vfat ESP mounted with default options, andlist-bootloadersandinstallup 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).--bootloader gruborsystemdEFI/redhat--bootloader grubEFI/extra/--bootloader gruborsystemd--bootloader systemd--bootloader grubEFI/fedora/SHIMX64.EFI,EFI/fedora/grubx64.efi., or a copy of GRUB asEFI/fedora/GRUBX64.EFI--bootloader gruborsystemd--bootloader gruborsystemdEFI/FEDORA--bootloader gruborsystemdEFI/fedoradirectory would fail.btmp.leftoverfile inusr/lib/efi--bootloader gruborsystemdEFI/fedora/help:debug.txtorEFI/fedora/notes.txt(a trailing space), names FAT cannot hold--bootloader gruborsystemdEFI/.BTMP.fedora, or an extra component withEFI/fedora/RELEAS~1--bootloader gruborsystemdtools/1/EFI/helper.efiin its legacy update directory--bootloader grubEFI/helper.efiusr/lib/efi/notes.txt--bootloader gruborsystemdEFI/FEDORAbeside shim'sEFI/fedora--bootloader grubEFI/fedora/GRUBX64.EFI, or asystemd-bootdirectory inside the GRUB component--bootloader grubAlso unchanged, proceeding with both:
--bootloader systemdon the Fedora 44 payloads where only GRUB is moved, renamed or given extra files, and--bootloader grubwith an identical copy of the GRUB binary at the same path in the shim component.Assisted-by: LLM