Commit Graph

73 Commits

Author SHA1 Message Date
Lennart Poettering
d71f2899bd meson: drop libblkid dep from components not using it directly 2025-09-24 18:11:12 +02:00
Lennart Poettering
a86a366eb0 bootctl: split out auto-enroll cert load code into function of its own 2025-09-20 00:47:46 +09:00
Lennart Poettering
407139ae92 bootctl: output a more precise log message when updating existing EFI vars 2025-09-20 00:47:46 +09:00
Lennart Poettering
7dd55c83b8 bootctl: don't update $ESP/EFI/BOOTX64.EFI twice
We update BOOTX64.EFI explicitly once (because we know that it's the
main entry point of UEFI) and then a second time when we update
everything in $ESP/EFI/*.EFI. That's redundant and pretty ugly/confusing
in the log output. Hence exclude the file we already updated explicitly
from the 2nd run.
2025-09-20 00:47:46 +09:00
Lennart Poettering
b6f4f85c39 bootctl: downgrade messages about foreign EFI files
Given that we iterate through $ESP/EFI/BOOT/*.EFI these days this is a
pretty common case, hence it's not really noteworthy, hence downgrade
these log messages from LOG_NOTICE to LOG_INFO.
2025-09-20 00:47:46 +09:00
Lennart Poettering
c95d72913a bootctl: split out varlink setup into a helper call of its own 2025-09-20 00:47:46 +09:00
Lennart Poettering
83d0b6597c bootctl: normalize some enum definitions 2025-09-20 00:47:46 +09:00
Lennart Poettering
f757022294 bootctl: use RET_GATHER() all over the place 2025-09-20 00:47:46 +09:00
Lennart Poettering
5c396a0110 bootctl: switch a few getenv() calls to secure_getenv()
Following the rule that we should always prefer the secure flavour over
the regular one unless there's a clear reason for the regular one, let's
switch this over. Better safe than sorry.
2025-09-20 00:47:46 +09:00
Yu Watanabe
bed2723caa bootctl: drop unnecessary verb_unlink()
It is a trivial wrapper for verb_list(). Let's directly use verb_list()
and drop verb_unlink().

Follow-up for 8702496bfb.
2025-09-17 14:35:45 +02:00
Antonio Alvarez Feijoo
5a70aa5315 bootctl: clarify that --secure-boot-auto-enroll requires a boolean value 2025-09-08 12:31:27 +02:00
Antonio Alvarez Feijoo
992716c9ab bootctl: fix reference to non-existent option in error log 2025-09-08 12:30:35 +02:00
Mike Yuan
1bc82e0c97 bootctl: make sure install verb also honors implied --graceful
Follow-up for bcc73cafdb
2025-09-05 04:45:33 +09:00
Yu Watanabe
37d1f1573b bootctl: do not fail on removing unfied kernel image
A boot loader entry for a unified kernel image has
BootEntry.kernel : path to the image relative to ESP or XBOOTLDR,
BootEntry.path   : path to the image.
Hence, these two effectively point to the same file.

Hence, by unlink command, the image is removed by
```
deref_unlink_file(&known_files, e->kernel, e->root);
```
then later tried again by
```
r = chase_and_unlink(e->path, root, ...);
```
and of course it fails with -ENOENT.

Let's ignore the failure there. We already ignore ENOENT on removal
at various places, especially in deref_unlink_file().

Fixes #38706.
Follow-ups for 8702496bfb.
2025-08-26 15:45:44 +02:00
Yu Watanabe
4279336618 chase: trigger automount only when explicitly requested
Since c5de7b14ae
file searching implies a new mount api syscall by default,
to trigger automounts.

But, this is not necessary in most cases, e.g. when chasing
syspath in sd-device (actually this causes regression in umockdev,
see https://github.com/martinpitt/umockdev/issues/271).
Another example is reading unit files, especially .network files,
as automount may trigger mounting network filesystems...

Also, when this is used in NSS plugins, programs that load the
plugins may fail because of spuriously configured seccomp. See #38565.

Let's not trigger automount by default, and do only when explicitly
requested.

This introduces CHASE_TRIGGER_AUTOFS, and use it in
- service manager,
- bootctl and finding ESP/xbootldr,
- sysupdate,
- mountfsd,
- systemd-mount.

There may be several more places we should trigger automount, but let's
do that later.

Follow-up for c5de7b14ae.
Fixes #38565.
Replaces #38569.

Co-authored-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-08-20 02:32:02 +09:00
Yu Watanabe
2e7d7e929e Revert "chase: invert CHASE_NO_AUTOFS and only set it where needed"
This reverts commit 490aa05ca1.

As commented https://github.com/systemd/systemd/pull/38569#discussion_r2284978273,
the commit makes autofs check bypassed. Before the commit, when
CHASE_NO_AUTOFS is set, we did not shortcut chasing paths, and refused
any autofs mount points in the path. However, with the commit, the flag
was swapped but even when CHASE_AUTOFS is unset, the autofs check may be
skipped.

To fix the issue, rather than swapping the flag, we should introduce
another flag, say CHASE_TRIGGER_AUTOFS. This revert the commit, and in a
later commit, the new flag will be introduced.
2025-08-20 02:15:36 +09:00
Luca Boccassi
490aa05ca1 chase: invert CHASE_NO_AUTOFS and only set it where needed
Since c5de7b14ae
file searching implies a new mount api syscall by default,
to trigger automounts.

This is problematic in NSS plugins, as they are dlopen'ed inside
processes by glibc, for two reasons.

First of all, potentially searching on a networked filesystem
automount could lead to nasty surprises, such as the process
responsible for setting up the network filesystem trying to
search on that same filesystem.

More importantly, the new mount api syscall was never part of
the filesystem seccomp filter that we provide by default, and
given mounting/remounting/bind mounting is one of the possible
ways to bypass sandboxing it is very likely not allowed when
custom filters are used in sandboxed processes, if they don't
need to do these operations otherwise.
The filesystem seccomp mask we provide has been updated, however
this only takes effect on the next restart of a service. When
systemd is upgraded via a package upgrade, the new nss plugin is
installed and will be immediately dlopen'ed by glibc when needed,
without waiting for the process to restart, which means the existing
seccomp filter applies, causing the filter to trigger.
Given it's not really possible for any arbitrary program to
predict which NSS modules glibc will load, given programs do not
configure that and instead nsswitch is set up by the sysadmin,
it's impossible to handle at each process level. It's also not
possible to know when it will be triggered, given the plugin
is not linked in each binary tools like need-restart cannot
even pre-emptively restart services that may be affected.

This means in practice, upgrading from systemd << v258 to >= v258
requires a reboot to avoid either subtle or catastrophic system
failures.

By avoiding to trigger automounts in nss-systemd we can avoid
both issues.

userdb drop-ins are searched for in:

/etc/userdb/
/run/userdb/
/run/host/userdb/
/usr/local/lib/userdb/
/usr/lib/userdb/

none of which are supported as automounts anyway.

Note that this happens only when the userdbd service is not running,
as otherwise nss-systemd will go through the varlink IPC, rather than
doing the searches in-process.

So invert CHASE_NO_AUTOFS to CHASE_AUTOFS and set it in the places where
we do want to trigger automounts, like looking for the ESP.

Follow-up for c5de7b14ae
Fixes https://github.com/systemd/systemd/issues/38565
2025-08-19 16:48:13 +02:00
Antonio Alvarez Feijoo
13358b7ce2 bootctl: specify that kernel image commands require a kernel image argument 2025-08-13 11:28:22 +01:00
Zbigniew Jędrzejewski-Szmek
57684a2554 bootctl: print location/status of loader.conf
The usual pattern of using colors to distinguish the mount path (/efi/)
and the rest is used. If the file cannot be read for reasons other than
-ENOENT, the error message is highlighted.

I considered a few places where to add this, but this section seems the
most reaosonable. We already print the 'token' there, which is also part of
the configuration.

Boot Loader Entry Locations:
          ESP: /efi (/dev/disk/by-partuuid/31659406-5a17-46ec-8195-0dea1667db58)
       config: /efi//loader/loader.conf
     XBOOTLDR: /boot (/dev/disk/by-partuuid/4f8a8fe9-4b45-4070-9e9b-a681be51c902, $BOOT)
        token: fedora
2025-07-29 11:36:21 +02:00
Luca Boccassi
bcc73cafdb bootctl: automatically set --graceful when running in chroot
Installing stuff in a chroot should not fail because efivars are
not available. When running in a container touching efivars is
completely disabled, but there are some cases (recovery) where
it is needed to touch them in a chroot, so don't disable them but
avoid failing the run instead.
2025-07-25 20:44:03 +01:00
Yu Watanabe
7f6086d530 tree-wide: do not use %m with SYNTHETIC_ERRNO() 2025-07-22 03:05:54 +09:00
Yu Watanabe
7107cfbf4f bootctl: do not fail when the same file is updated multiple times
In the second or later trial, copy_file_with_version_check() -> version_check()
fails with -ESRCH. Let's ignore the failure.

This also adds missing assertions in update_efi_boot_binaries(), and
drop redundant version check in update_efi_boot_binaries(), as version
will be anyway checked later.

Fixes a regression caused by 929f41c652.
Fixes #33392.
2025-07-21 16:07:08 +01:00
Luca Boccassi
6eab4cd44c boot: add LoaderTpm2ActivePcrBanks runtime variable
It turns out checking sysfs is not 100% reliable to figure out whether
the firmware had TPM2 support enabled or not. For example with EDK2 arm64, the
default upstream build config bundles TPM2 support with SecureBoot support,
so if the latter is disabled, TPM2 is also unavailable. But still, the ACPI
TPM2 table is created just as if it was enabled. So /sys/firmware/acpi/tables/TPM2
exists and looks correct, but there are no measurements, neither the firmware
nor the loader/stub can do them, and /sys/kernel/security/tpm0/binary_bios_measurements
does not exist.

The loader can use the apposite UEFI protocol to check, which is a more
definitive answer. Given userspace can also make use of this information, export
the bitmask with the list of active banks as-is. If it's not 0, then we can be
sure a working TPM2 was available in EFI mode.

Partially fixes https://github.com/systemd/systemd/issues/38071
2025-07-14 20:56:22 +01:00
Yu Watanabe
83a047fe23 tree-wide: include sys/stat.h where necessary
These source files uses symbols provided by sys/stat.h, e.g. struct stat,
S_IFREG, S_IFBLK, and so on. Let's explicitly include sys/stat.h where
necessary.

Glibc's fcntl.h includes bits/stat.h, which provides these symbols, so
these symbols can be used without explicitly including sys/stat.h. But,
based on the discussion in #37922, we should explicitly include relevant
headers, and should not rely on the indirect inclusion.

Similar to 4f18ff2e29, but for sys/stat.h.
2025-07-07 12:44:10 +09:00
Lennart Poettering
6b8770b96b bootctl: when updating everything check PE machine type
Let's never accidentally over-write foreign-arch PE binaries with native
ones.

Fixes: #33413
2025-06-20 14:06:53 +02:00
Lennart Poettering
95df8288c7 bootctl: be more careful when opening arbitrary files from ESP
Let's refuse all kind of weird stuff early.

As suggested here: https://github.com/systemd/systemd/pull/30418#pullrequestreview-2128220792
2025-06-20 14:06:53 +02:00
Joaquim Monteiro
c9e614eb25 bootctl: fix unclosed quote in debug log 2025-06-01 11:34:17 +09:00
Yu Watanabe
91c60ff528 bootctl: do not print slash more than once
When bootctl is called by an unprivileged user, then previously we got
```
Failed to read "/boot/EFI/systemd": Permission denied
Failed to open '/boot//loader/loader.conf': Permission denied
```
Now, with this patch, we get
```
Failed to read "/boot/EFI/systemd": Permission denied
Failed to open '/boot/loader/loader.conf': Permission denied
```
2025-05-31 13:53:04 +02:00
Daan De Meyer
f712008289 bootctl: Clean up includes
Split out of #37344.
2025-05-22 02:14:09 +09:00
Zbigniew Jędrzejewski-Szmek
5270c085d4 bootctl: prefix all paths with the mountpoint prefix
Continuation of 7851732262 and
5a65d2e535. Absolute paths are always
nicer for the user because it's much easier to figure out where the
file is located. And printing some paths with the prefix and some
without was quite confusing.
2025-05-20 18:20:36 +02:00
Zbigniew Jędrzejewski-Szmek
e187450648 bootctl: rework Boot Loader Entries section in status
Kernels are loaded from two partitions (XBOOTLDR and ESP). In the past this
wasn't always so, but a while ago the docs and the code were updated to load
from both locations. The $BOOT location specifies where to install only. So
rework the status output to print both locations and indicate which one is
$BOOT by appending ", $BOOT".

Also change the section title to "… Locations". We don't show *entries* here,
so the old title could be a bit confusing.

Example:
Boot Loader Entry Locations:
          ESP: /efi (/dev/disk/by-partuuid/31659406-5a17-46ec-8195-0dea1667db58)
     XBOOTLDR: /boot (/dev/disk/by-partuuid/4f8a8fe9-4b45-4070-9e9b-a681be51c902, $BOOT)
        token: fedora
2025-05-20 18:20:28 +02:00
Jelle van der Waa
346c62f9ca treewide: correct argument comments 2025-05-15 15:39:20 +02:00
Igor Opaniuk
2857a83975 bootctl: configure a sysfail entry
You can configure the sysfail boot entry using the bootctl command:
$ bootctl set-sysfail sysfail.conf

The value will be stored in the `LoaderEntrySysFail` EFI variable.

The `LoaderEntrySysFail` EFI variable would be unset automatically
during next boot by `systemd-boot-clear-sysfail.service` if no
system failure occured, otherwise it would be kept as it is and a system
failure reason will be saved to `LoaderSysFailReason` EFI variable.

Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
2025-05-12 15:37:47 +02:00
Daan De Meyer
e53d4f343d iovec-util: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Daan De Meyer
6553db6063 strv: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Yu Watanabe
13e4201dc9 Bugprone argument comments - round 3 (#37356)
Follow up from https://github.com/systemd/systemd/pull/37346
2025-05-07 01:38:34 +09:00
Daan De Meyer
1fbfbe81b5 tree-wide: Get rid of prefix_roota() in favor of path_join()
We deprecated prefix_roota() in favor of chase() and path_join().
Let's finish the removal by replacing the few remaining call sites
with path_join().
2025-05-06 17:40:33 +02:00
Jelle van der Waa
1c04b172f1 treewide: correct argument comments for show_boot_entry 2025-05-06 16:26:47 +02:00
Daan De Meyer
1cf40697e3 tree-wide: Sort includes
This was done by running a locally built clang-format with
https://github.com/llvm/llvm-project/pull/137617 and
https://github.com/llvm/llvm-project/pull/137840 applied on all .c
and .h files.
2025-04-30 09:30:51 +02:00
Yu Watanabe
cdf3339c56 bootctl: fix typo
Follow-up for bbeeea4362.
2025-04-19 04:49:29 +09:00
Daan De Meyer
93a1f7921a basic: Stop including log.h in macro.h
Now that the necessary functions from log.h have been moved to macro.h,
we can stop including log.h in macro.h. This requires modifying source
files all over the tree to include log.h instead.
2025-04-18 14:19:15 +02:00
Lennart Poettering
bbeeea4362 bootctl: replace --no-variables by --variables=BOOL
I think the current behaviour of not doing EFI variables when we are run
in a container makes a ton of sense, but in some cases it's useful to
do EFI var setup even when a set of namespaces is set up for us, for
example to recover a hosed installation from a rescue disk.

While we are at it, let's remove some duplicate checks, and
systematically output information why we skip various operations.

Fixes: #36174 #35005
2025-04-16 13:39:12 +02:00
Daan De Meyer
69369fd322 bootctl: adjust feature message (#36372) 2025-03-21 11:17:00 +01:00
Zbigniew Jędrzejewski-Szmek
6012a52aba bootctl: do not print special glyphs to the log
The log line looked like this:
  bootctl[1457]: ! Mount point '/efi' which backs the random seed file is world accessible, which is a security hole! !
which doesn't look nice.

Also upgrade the message to error. This is something to fix.
2025-03-15 14:40:52 +01:00
Zbigniew Jędrzejewski-Szmek
1ae9b0cfa8 basic/glyph-util: rename "special glyph" to just "glyph"
Admittedly, some of our glyphs _are_ special, e.g. "O=" for SPECIAL_GLYPH_TOUCH ;)
But we don't need this in the name. The very long names make some invocations
very wordy, e.g. special_glyph(SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY).
Also, I want to add GLYPH_SPACE, which is not special at all.
2025-03-15 14:40:39 +01:00
Zbigniew Jędrzejewski-Szmek
16fa8dbbe9 bootctl: fix boolean logic in id128 comparisons
There were too many levels of negation there. Add a comment to explain the
reasoning at a high level.
2025-03-14 12:21:45 +01:00
Zbigniew Jędrzejewski-Szmek
f25e4e5af0 bootctl: stop printing "Stub/Boot loader set partition information"
... and "Stub/Boot loader set network boot URL information".

This reverts 26bfd97216
('bootctl: also shown whether stub loader partition data was passed'),
and one line from bfcf48b842
('bootctl: show stub partition data too in "status" too'),
and two lines from e15d18b4c6
('sd-stub: if we are http booted, query source URL and write to EFI variable').

As discussed in https://github.com/systemd/systemd/pull/36372, those are not
"features", but optional pieces of information that may or may not be set, also
depending on how the boot loader and stub were loaded. We already prominently
show this information right below: either we print the device path or "n/a" or
skip the output. The user already has all the information, and the status
output should be dense, so it doesn't make sense to repeat this twice.

               ✓ Boot loader set partition information
    Partition: /dev/disk/by-partuuid/3f003ec5-5673-5b4f-b9a4-cbac1ca4461a
OR
               - Boot loader set partition information
    Partition: n/a

               ✓ Stub loader set partition information
    Partition: /dev/disk/by-partuuid/3f003ec5-5673-5b4f-b9a4-cbac1ca4461a
OR
               - Stub loader set partition information
    Partition: n/a
2025-03-13 12:30:59 +01:00
Lennart Poettering
a462280c9a bootctl: tweak status output when operating on --image= files
Let's not claim the system was not booted with UEFI if we use --image=.
The system wasn't booted at all, after all. Hence supress the whole
section altogether in this case.
2025-03-13 10:49:53 +01:00
Lennart Poettering
742e26ba20 bootctl: make sure bootctl --image= works on image with /usr/ but without /
Let's make sure we can use the tool on ParticleOS images. They have no
root fs by default (until they are instantiated), but always have /usr/.
Hence add DISSECT_IMAGE_USR_NO_ROOT which has the desired effect.
2025-03-13 10:49:33 +01:00
Lennart Poettering
14871a6529 efivars: kill SystemdOptions efi var support
This has been depracted since v254 (2023). Let's kill it for
good now, it has been long enough with 2y. Noone has shown up who wants
to keep it. And given it doesn't work in SB world anyway, and is not
measured is quite problematic security wise.
2025-02-26 17:28:43 +01:00