Commit Graph

1761 Commits

Author SHA1 Message Date
Thomas Mühlbacher
226e050a0d stub: check load options a little more carefully
This can lead to booting with a completely garbled command line with characters
being interpreted as miscellaneous CJK or symbols.

According to the UEFI spec, the optional data of the load option is just a
binary data buffer.
2025-10-20 10:28:41 +02:00
Duy Nguyen Van
7ae7c014c3 Fix build fail when add option "-fstack-protector-all"
When using canary check with "-fstack-protector-all" option. It causes a configure
error in systemd-boot when meson.build executes compile simple code to test linker option
"-static-pie" because -nolibstd option prevents using libc. It need for
canary to provide some function as "__stack_chk_guard". So need to turn off
canary check when compile sanity check.
2025-10-13 10:27:28 +02:00
Yu Watanabe
b49bff0da7 shared/bootspec: don't warn for new loader.conf options and correctly parse new uki and profile boot entry options (#39165)
Commit e2a3d56218 added the `uki` option
to sd-boot, and 1e9c9773b9 added
`profile`, but because these were not added in src/shared/bootspec,
bootctl still shows warnings like `Unknown line 'uki', ignoring.` when
parsing the config. This PR allows parsing and displaying them correctly
in `bootctl` output. It also stops it from printing a warning for any of
the new `loader.conf` options (`log-level`, `reboot-on-error`, etc.).
Note that `uki-url` is still not handled as I can't easily test it.
2025-10-04 23:35:54 +02:00
Zbigniew Jędrzejewski-Szmek
ea44302b29 meson: using f-strings in meson
Those were added before 0.61 which is our minimum version.

Dots were dropped from the end of some messages. Most messages did not have the
trailing dot.

0.63 added support for multi-line f-strings. We can't use those yet.
2025-10-03 21:21:52 +02:00
Felix Pehla
0b89d8cfec shared/bootspec: update valid loader.conf options 2025-09-29 23:46:59 +02:00
Felix Pehla
39179ac5fe sd-boot: fix indentation of status output
64376936c7 missed some printf()s when
adjusting indentation.
2025-09-28 09:50:19 +09:00
Itxaka
1e9c9773b9 Parse a new profile key in Type 1 boot entries
This allows Type 1 entries to take advantage of multiprofile efi files
by allowing the configuration of the profile associated with that entry.

It will now parse the profile key in a Type 1 config to select that
profile when booting that efi file instead of relaying in the cmdline

Signed-off-by: Itxaka <itxaka@kairos.io>
2025-09-26 10:00:43 +02:00
Yu Watanabe
513d91a159 boot: two trivial cleanups (#39093) 2025-09-24 23:18:00 +09:00
Lennart Poettering
e27a530919 boot: let's make the one space we output early on invisible
let's place the cursor at the beginning of the line before/after, so we
know it's the first char we overwrite, and we return to the front again
right after.
2025-09-24 12:33:59 +02:00
Lennart Poettering
f417a984c9 boot: return to beginning of line when enrolling 2025-09-24 12:33:59 +02:00
Lennart Poettering
8d36341cef boot: work around ansi color issues between sd-boot, uefi and terminals
So, UEFI's color texting is a bit weird. It translates everything to
ANSI sequences, but unlike ANSI sequences it has no understanding of a
distinct "default" bg/fg color, it assumes the ansi color "0" is always
equal to white on black, but that's of course not really true, most
terminal emulators at the very least support white background too.

tianocore then also tries to be smart and suppresses ANSI color changes
from a color to itself. But if the understanding of the color is wrong
in the first place, then any color change suppression like this hurts
more than it helps.

Then in addition there are certain terminal tools that will reset the bg
color on every line break ("less" for example) to the default.

Let's deal with that and improve the situation on all fronts:

1. force out color changes by doing two color changes whenever we really
   want it.

2. on every newline force out the color change again.

with this in place, using sd-boot on a terminal emulator is a lot nicer.
2025-09-24 12:33:59 +02:00
Yu Watanabe
63dd548fb4 boot: rename ENROLL_TIMEOUT_TYPE_MAX -> ENROLL_TIMEOUT_MAX
To make it consistent with ENROLL_TIMEOUT_MIN.

Follow-up for 64376936c7.
2025-09-24 18:22:12 +09:00
Yu Watanabe
2e3c792baf boot: use correct format specifier for timeout
This also drops space between number and 's', like we do in format_timespan(),
and fixes spurious type mismatch between timeout_sec and timeout_remain.
2025-09-24 18:20:10 +09:00
Lennart Poettering
b388fa20c7 boot: check protocol version before assuming GetActiveBanks() exists
Alternative to: #39034
Fixes: #38932
Follow-up to: 6eab4cd44c
2025-09-24 08:57:11 +02:00
Lennart Poettering
496489c2a7 measure: strip tpm 1.x remnants
Let's never bother with old TPM 1.x structures, they are not mentioned
in the TCG for TPM2 spec at all. However, the spec does say we should
check the Size field of the relevant structs, before accessing them,
hence do that.
2025-09-24 08:49:23 +02:00
Igor Opaniuk
64376936c7 boot: add support for overriding key enrollement timeout
Currently, a 15-second timeout is hardcoded for the key enrollment
process while waiting for user confirmation. Make this value configurable
to allow the option of disabling user input, such as during automatic key
provisioning at the factory.

Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
2025-09-23 12:13:10 +02:00
Yu Watanabe
0c25f8fd0b sd-boot: allow configuration of log levels (#38701)
This allows for more liberal usage of logging functionality as messages
will no longer always show up on screen, regardless of urgency. The log
level to use can be configured through an SMBIOS type 11 string
(`io.systemd.boot.loglevel=`) or by using the `log-level` option in
loader.conf. Valid values are debug, info, notice, warning, err, crit,
alert, and emerg. By default, info will be used.
2025-09-18 12:06:48 +09:00
Tobias Heider
f405165065 stub: fix file path handling for loaded kernel
- Actually pass the new memory file path to parent_loaded_image->FilePath
- Restore old parent_loaded_image if Linux returns
- Pass the same kernel_file_path in load_via_boot_services path
- s/Re-use/Patch in comment explaining what we are doing

Fixes #38566
2025-09-18 11:40:43 +09:00
Yu Watanabe
c6e6c85f83 test: several random cleanups and fixlets (#38877) 2025-09-18 09:13:17 +09:00
Felix Pehla
b3f3ce28f8 sd-boot: allow setting the log level through loader.conf
Allow configuring the log level used by sd-boot by setting
`log-level=<level>` in loader.conf. `info` is used by default.
2025-09-18 08:54:52 +09:00
Felix Pehla
0ce83b8a57 sd-boot: allow setting the log level through SMBIOS 11
Allow configuring the log level used by sd-boot by setting
`io.systemd.boot.loglevel=<level>` as SMBIOS type 11 string.
`info` is used if unset.
2025-09-18 08:54:52 +09:00
Felix Pehla
4f35d74998 sd-boot: allow setting the maximum log level 2025-09-18 08:54:52 +09:00
Felix Pehla
419e4dc450 sd-boot: efi-log: use log levels internally
Change log_internal() to receive a log level from which a text color is
derived, rather than the text color directly, and adjust various log_*
macros to use them internally.
2025-09-18 08:54:52 +09:00
Yu Watanabe
ddd2590a4e Align meson summary and gperf tables (#38578)
No functional change, just refactoring.
2025-09-18 08:44:08 +09:00
Danilo Spinella
4301ad00ef boot: Strip boot counter from entry id
When boot counter is found in the boot entry filename, strip it from the
id to match bootctl id.

Fixes #38813.
2025-09-17 19:43:37 +01:00
Lennart Poettering
6413ccc625 sd-boot: rename "path" field to "directory"
"path" sounds like a fully qualified complete string referencing some
terminal object. But here it's not like that, the field just stores the
directory the object we actually care about is placed in. Hence let's
change this field to be named "directory", to be less confusing for
readers.
2025-09-17 15:40:05 +02:00
Yu Watanabe
5809c451e8 test-efi-string: migrate to use ASSERT_OK() and friends 2025-09-17 22:20:42 +09:00
Yu Watanabe
f56c036fd3 meson: realign summary 2025-09-17 22:07:27 +09:00
Yu Watanabe
eb654a769d boot: add assertions
To silence coverity.

Closes CID#1620098.
2025-09-17 14:18:54 +02:00
Luca Boccassi
8f6236164c boot: also remember auto-generated entries
Windows/OSX/shell/etc entries are autogenerated, and should be remembered too
as the previous choice, together with Linux ones.

Follow-up for d870ae47b7

Fixes https://github.com/systemd/systemd/issues/38694
2025-08-25 23:45:12 +09:00
Felix Pehla
ddc9d2a836 systemd-boot: don't always log NX_COMPAT info
Commit 70b7e03 introduced 3 calls to log_debug() about the presence or
absence of NX_COMPAT support. Since sd-boot does not yet have the
ability to only print messages above a certain loglevel, these will
always be printed, even on top of the configured splash screen. This
commit removes the log_debug() call after a success and only prints
those for missing firmware support if the UEFI should support them in
the first place (i.e. starting with version 2.10).
2025-08-25 13:40:54 +01:00
Luca Boccassi
1441f2e992 Add padding to sbat section (#38621) 2025-08-19 17:49:07 +01:00
Luca Boccassi
70b7e03ebb sd-stub: use memory proto if available and set kernel memory to RX with NX_COMPAT
When NX_COMPAT gets enabled, firmwares will enforce that executable
memory is either writable or executable.
This needs kernel compatibility, when it will happen the kernel will
have the NX_COMPAT bit set. If it is, set the memory buffer to RO.

Note that this must be undone on failure, as EDK2 in some configurations
overwrites memory ranges that are returned with FreePages() with a
fixed pattern, so if the pages are RO it will crash.

This is only an issue with the new custom PE loader, as LoadImage()
and StartImage() will always do the right thing automatically.

https://microsoft.github.io/mu/WhatAndWhy/enhancedmemoryprotection/
https://www.kraxel.org/blog/2023/12/uefi-nx-linux-boot/

Follow-up for cab9c7b5a4

Fixes https://github.com/systemd/systemd/issues/38545
2025-08-19 17:16:57 +02:00
Zbigniew Jędrzejewski-Szmek
b4a1854397 sd-boot: pad .sbat section to 1k bytes
Fedora's kernels now ship with a .sbat section:
  kernel,1,Red Hat,kernel-core,6.17.0-0.rc1.250814g0cc53520e68b.20.fc44.x86_64,mailto:secalert@redhat.com
  kernel.fedora,1,Red Hat,kernel-core,6.17.0-0.rc1.250814g0cc53520e68b.20.fc44.x86_64,mailto:secalert@redhat.com
This pushes the combined .sbat section just over its pre-allocated size of 512 bytes:
  File "/usr/bin/ukify", line 1048, in pe_add_sections
    raise PEError(f'Not enough space in existing section {section.name} to append new data')
  PEError: Not enough space in existing section .sbat to append new data

PE sections need to align to 512 bytes, so to make it all fit we pad the .sbat
section with zeros to 1k. Various tools already should strip trailing zeros when
using sbat sections, since ukify always inserts a trailing NUL.

The defines are moved to sbat.h, they are used only in sd-stub and sd-boot.
2025-08-19 11:50:27 +02:00
Mate Kukri
428cd7bfba Reuse the parent_image handle and parent_loaded_image
- Reuse parent_image instead of allocating new ones. Firmware might cast
  EFI_LOADED_IMAGE_PROTOCOL * to a larger struct causing issues
- Remove loaded image protocol installation and uninstallation which are no
  longer required

Fixes a bug introduced by cab9c7b5a4.
Fixes #38567.

Co-authored-by: Tobias Heider <tobias.heider@canonical.com>
2025-08-14 19:59:37 +09:00
Tobias Heider
5a64f158ec chid: don't hardcode magic numbers for non-official CHIDs
They are constructed from EXTRA_CHID_BASE + offset
2025-08-11 11:18:53 +02:00
Luca Boccassi
9cd3e63014 stub: also pickup global .raw sysexts, like per-UKI ones
It is extremely confusing to use different filenames for different
locations, so pick up the same images for both per-UKI and global
extensions

Follow-up for 9f7e3820e9
2025-08-05 17:06:15 +02:00
Luca Boccassi
bef244392b stub: fix passing kernel cmdline when loading via shim
This was mistakenly dropped when the custom PE loader was added.
Add it back, otherwise no smbios/addon cmdline options are passed
through.

Fixes https://github.com/systemd/systemd/issues/38349

Follow-up for 40aabfae72
2025-07-27 22:44:05 +01:00
Yu Watanabe
635894a493 fuzz-efi-string: add missing OOM check
Fixes CID#1610113 and CID#1610114.
2025-07-26 05:00:02 +09:00
Zbigniew Jędrzejewski-Szmek
c5dcbd073e meson: use files() not find_program() for helper scripts
We went back and forth between 'prog.sh', files('prog.sh'), and
find_program('prog.sh'). We want to use files() or find_program() so that we
get a good error message if the file is missing. Behaviour of meson changed
over time, and in the past not all forms could be used in all places. For
example 0f4c4f3824 added find_program() in many
places to avoid repeated messages. But it seems that all recent meson versions
work fine with files().

find_program prints silly messages:
  Program tools/make-man-index.py found: YES
       (/home/zbyszek/src/systemd/tools/make-man-index.py)
  Program tools/meson-render-jinja2.py found: YES
       (/home/zbyszek/src/systemd/tools/meson-render-jinja2.py)
  ...
We know that those files will be found, they are part of the git checkout.
With files() this is gone and the meson output is easier to read.
2025-07-25 14:04:17 +02:00
Zbigniew Jędrzejewski-Szmek
8aedfd979f tools: make all .py program files executable
All those files are standalone programs that can be executed directly.
Some .py files were marked executable, others weren't, probably accidentally.
Mark them all as executable in preparation for subsequent changes.
2025-07-25 12:33:13 +02:00
Luca Boccassi
5115710528 stub: check if security override is available before using it
Avoids fallback that requires it if it is not available. Can
be dropped once support for shim < 16 is no longer needed

Follow-up for 23d56ae890
2025-07-23 10:29:19 +01:00
Zbigniew Jędrzejewski-Szmek
dcccbe049c tree-wide: several fixlets for log message and comment (#38263) 2025-07-23 10:17:33 +02:00
Luca Boccassi
23d56ae890 stub: restore compatibility for shim (< 16.0) -> UKI case
It is possible to boot directly a UKI from shim, and Fedora Cloud Base UKI
does exactly this.
This used to work fine until https://github.com/systemd/systemd/pull/37372
which broke compatibility when shim < 16.0 (no loader protocol override) is
used. Shim 15.8 is still in use in several distributions, and will be for
a long time.

Restore a part of the previous implementation, and if running with secure
boot enabled, and with shim but < 16.0, apply a security override.

Follow-up for cab9c7b5a4

Fixes https://github.com/systemd/systemd/issues/38104
2025-07-23 09:54:09 +02:00
Yu Watanabe
de69562623 tree-wide: add missing '=' in short comments for function argument 2025-07-22 03:05:54 +09:00
Yu Watanabe
5918ba9c69 tree-wide: fix log messages: "Failed VERB" -> "Failed to VERB" 2025-07-22 03:05:33 +09:00
Zbigniew Jędrzejewski-Szmek
e884fcb6b5 boot: move/adjust comments
The comment in linux_exec() was based on Lennart's comment in
https://github.com/systemd/systemd/pull/37372#discussion_r2142340582, but
shortened. The original wording is more direct and at least for me easier to
grok, so adjust the comment to be more verbose again.

Also, move the comment from shim_loader_available() to the place where it used.
This function is for checking if the new thing is available, no need to describe
the old thing there.
2025-07-17 17:10:18 +02: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
DaanDeMeyer
1408505318 meson: Fix missing test dependencies
These test would fail when executed directly with meson test before
doing a build because the required dependencies are not declared, let's
fix that.
2025-07-14 13:07:29 +01:00
DaanDeMeyer
d962bfeb03 boot: Use hypen in efi-config.h instead of underscore 2025-07-13 12:41:57 +02:00