Commit Graph

1661 Commits

Author SHA1 Message Date
Lennart Poettering
395ac1c448 boot: split out call that adds reboot/poweroff/firmware entries 2025-02-25 21:15:10 +01:00
Lennart Poettering
612bc71210 boot: make secure boot enrollment less special
This is the last entry type that has special handling: with this in
place we now always invoke entry handlers the very same way. via the
.call() method of the BootEntry structure.
2025-02-25 21:15:10 +01:00
Lennart Poettering
fb09163a01 boot: move check if secure boot enrollment applies to a single place
Let's check if sb enrollment applies at a single place: inside the
discovery function, and let's not bother with additional checks later.
2025-02-25 21:15:10 +01:00
Lennart Poettering
fb6cf4bbb7 boot: make regular entries less special
Let's try to always invoke entries via the call() method of BootEntry
objects, to stick to a single uniform way to do so.
2025-02-25 21:15:10 +01:00
Lennart Poettering
d870ae47b7 boot: only save entry for some entry types
Much like the previous one, let's also condition the entry selection
saving on entry types.
2025-02-25 21:14:27 +01:00
Lennart Poettering
ae5e7f17d0 boot: only do random seed management for some entry types
Similar to the previous commits, let's carefully condition random seed
management (which might be slow, and simply pointless for various entry
types) on the entry type.
2025-02-25 21:14:27 +01:00
Lennart Poettering
729f3c21c5 boot: only do boot counting management for some menu entries
Let's do boot counting only for some menu entry types, and carefully
list which types those are.
2025-02-25 21:14:27 +01:00
Lennart Poettering
4801e16401 boot: make .call() method of BootEntry more complete
Let's pass some context information to the .call() methods so that it's
sufficient to implement the handlers for all entry types with them.

(This commit doesn't port the various entry types over though, that
happens in later commits.)
2025-02-25 21:14:27 +01:00
Lennart Poettering
95086da39f boot: split out line editor
let's make this beast of boot.c a bit more digestable
2025-02-25 21:08:38 +01:00
Lennart Poettering
fc8f0089bf boot: when we detect that sd-boot is called as NBP, print friendly message
Fixes: #11850
2025-02-21 10:04:15 +01:00
Lennart Poettering
4f3a3b7695 sd-boot: also read type #1 entries from SMBIOS Type #11
With this we can now do:

systemd-vmspawn -n -i foobar.raw -s io.systemd.boot.entries-extra:particleos-current.conf=$'title ParticleOS Current\nuki-url http://example.com/somedir/uki.efi'

Assuming sd-boot is available inside the ESP of foobar.raw a new item
will show up in the boot menu that allows booting directly into the
specified UKI.
2025-02-21 10:04:15 +01:00
Lennart Poettering
1089d0f89e boot: add new 'uki-url' bls type #1 menu items for booting remote UKIs
Companion BLS spec PR:

https://github.com/uapi-group/specifications/pull/135
2025-02-21 10:04:15 +01:00
Lennart Poettering
e2a3d56218 boot: add new bls type #1 stanza "uki"
This one is between "efi" and "linux": we'll recognize such entries as
linux, but we'll just invoke them as EFI binaries.

This creates a high-level concept for invoking UKIs via indirection of a
bls type #1 entry, for example to permit invocation from a non-standard
path or for giving entries a different name.

Companion BLS spec PR:

https://github.com/uapi-group/specifications/pull/135

(Let's rename LOADER_UNIFIED_LINUX to LOADER_TYPE2_UKI at the same time
to reduce confusion what is what)
2025-02-21 10:04:15 +01:00
Lennart Poettering
06648d4187 boot: move behaviour checks into per-entry-type helpers 2025-02-21 10:04:15 +01:00
Lennart Poettering
149609cfcb boot: be stricter when filtering out invalid bls #1 entries 2025-02-21 10:04:15 +01:00
Lennart Poettering
a6fbfd8db6 boot: bls type #1 with 'efi' stanza are bls type #1 too 2025-02-21 10:04:15 +01:00
Lennart Poettering
f684168050 efi: add strcspn16()/strspn16() to efi libs too 2025-02-21 10:04:15 +01:00
Lennart Poettering
d9d3e9d6c1 efi-string: add new xstr16_to_ascii() helper 2025-02-21 10:04:15 +01:00
Lennart Poettering
e577d7d94a efi: modernize reconnect_all_drivers() a bit 2025-02-21 10:04:15 +01:00
Lennart Poettering
e15d18b4c6 sd-stub: if we are http booted, query source URL and write to EFI variable
This way userspace can read the field, and use it to retrieve more
resources from the same place.
2025-02-21 10:03:32 +01:00
Yu Watanabe
576e98a72c meson: fix suite of alignment check tests
Follow-up for 97318131fd.

By default, suite of each built test is determined by the directory of
the source file. Hence, before the mentioned commit, all tests in
src/boot/efi/ are in the 'efi' suite. The commit changed the directory
tree, but forgot to update the name of the test suite.
2025-02-08 00:13:28 +00:00
Yu Watanabe
52a0bf1621 boot: rename efifirmware.[ch] -> efi-firmware.[ch]
This also
- renames efifirmware_match_by_fwid() -> efi_firmware_match_by_fwid(),
- drops unnecessary wrapper efifw_get_fwid(),
- drops unnecessary inclusion of header <endian.h>,
- sort files in meson.build.

No functional change, just refactoring and follow-ups for
83bf58f39d.
2025-02-01 13:54:01 +09:00
Ani Sinha
83bf58f39d uki: introduce support for a .efifw section
UKIs can be used to bundle uefi firmwares that can be measured and
used on a confidential computing environment. There can be more than one
firmware blob bundle, each one for a specific platform. Also firmware images
can themselves be containers like IGVM files that can in turn bundle the
actual firmware blob. This change is specifically for uefi firmwares, not
IGVM container files.

This change adds support to introduce a .efifw section in UKI that can be
used for firmware blobs/images. There can be multiple such sections and each
section can contain a single firmware image.

The matching .hwids entry for a specific platform can be used to select the
most appropriate firmware blob.

ukify tool has been also changed to support addition of a firmware image
in UKI.

Since firmware gets measured automatically, we do not need to measure it
separately as a part of the UKI.
2025-01-31 10:05:00 +01:00
Daan De Meyer
ff83795469 boot: Improve log message 2025-01-26 10:20:06 +09:00
Yu Watanabe
d7306348b2 tree-wide: insert a space at the end of comments 2025-01-25 05:24:23 +09:00
Yu Watanabe
a8fe005209 tree-wide: drop merely used _cleanup_ macros, and introduce several new ones (#36071) 2025-01-21 03:41:27 +09:00
Yu Watanabe
99de29945f tree-wide: coding style fixlets done by coccinelle 2025-01-19 08:28:42 +09:00
Yu Watanabe
7eabb5ca61 boot: introduce _cleanup_strv_free_ 2025-01-19 04:18:04 +09:00
Yu Watanabe
6ea99fd2cf boot: introduce _cleanup_file_close_ 2025-01-19 04:15:27 +09:00
Yu Watanabe
9c881fa867 fundamental-macro: conditionalize several gcc warning pragmas
This fixes the following error:

In file included from ../src/basic/macro.h:13,
                 from ../src/basic/env-util.h:9,
                 from ../src/nss-systemd/nss-systemd.c:7:
../src/fundamental/macro-fundamental.h:61:9: error: option ‘-Wzero-as-null-pointer-constant’ is valid for C++/ObjC++ but not for C [-Werror=pragmas]
   61 |         _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"")
      |         ^~~~~~~
../src/nss-systemd/nss-systemd.c:106:1: note: in expansion of macro ‘DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT’
  106 | DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
2025-01-17 04:35:09 +09:00
Luca Boccassi
8c5b359579 stub: drop PE sections parsing cap
This was added originally as it was thought that Windows applied
the same cap. Nowadays the specs do not mention it, and it is
believed Windows no longer applies it either, so drop it in order
to allow an arbitrary number of DTBs to be included

Fixes https://github.com/systemd/systemd/issues/35943
2025-01-10 22:51:46 +00:00
Ani Sinha
5d614bae74 chid_match: match only against the provided device type
When devices of different types are present, chid_match() should only try to
match the devices that are of specific type. The caller of chid_match()
provides the type of device to match against and chid_match() should only try
to find a match against this device type.

This change also adds necessary unit test changes for the new uefi firmware
type device entry.
2025-01-05 09:40:55 +05:30
Ani Sinha
5d0ac3528b hwids: add a new uefi firmware type of device entry
This change adds a new uefi firmware type device entry for the .hwids section.
It also adds necessary changes for ukify.py.
2025-01-05 09:40:05 +05:30
Ani Sinha
fde7adab3b Use device3.xml for testing chid_match
device3.xml was not used. Use it now.
2024-12-22 18:29:03 +00:00
Antonio Alvarez Feijoo
5aab7ad075 boot: do not build test-hwids-section.c if ukify is disabled
Otherwise the build fails:

```
[22/3075] Generating src/boot/test-hwids-section.c with a custom command (wrapped by meson to capture output)
FAILED: src/boot/test-hwids-section.c
/usr/bin/meson --internal exe --capture src/boot/test-hwids-section.c -- /usr/bin/python3.10 /mnt/work/systemd/upstream-fork/main/src/boot/generate-hwids-section.py /mnt/work/systemd/upstream-fork/main/src/boot/hwids
--- stderr ---
Traceback (most recent call last):
  File "/mnt/work/systemd/upstream-fork/main/src/boot/generate-hwids-section.py", line 12, in <module>
    import ukify
  File "/mnt/work/systemd/upstream-fork/main/src/boot/../ukify/ukify.py", line 61, in <module>
    import pefile  # type: ignore
ModuleNotFoundError: No module named 'pefile'
```

Follow-up for 640f8c3eb8
2024-12-17 11:15:39 +00:00
anonymix007
640f8c3eb8 test: Add test-chid-match 2024-12-16 21:02:54 +03:00
Yu Watanabe
7c4e351861 boot: introduce smbios_raw_info_get_cached() to cache populated SMBIOS raw info
Then, drop cache in smbios_info_populate().
No functional change, just refactoring and preparation for later commit.
2024-12-16 21:02:54 +03:00
anonymix007
f28cedfa31 boot: Add chid.c to libefitest
Also fix compilation for testing CHID matching in userspace
2024-12-16 21:02:54 +03:00
anonymix007
48acd7fe90 boot: Deduplicate efi.h and efi-fundamental.h
These definitions are needed for both userspace and EFI, so keep them in efi-fundamental.h
2024-12-16 21:02:54 +03:00
Samuel Dionne-Riel
67f8ddc967 boot: Fix typo in looking_for_dtbauto
Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
2024-12-10 20:59:18 +01:00
Zbigniew Jędrzejewski-Szmek
423de11f04 boot: exclude the trailing padding from initrd size in initrd_prepare()
This is a follow-up for f8fa4222c9 (boot: Make
initrd_prepare() semantically equivalent to combine_initrds()). That commit
changed the way that the initrd is prepared for type#1 boot loader entries,
also effectively rounding up the sizes to a multiple of 4. In [1], downstream
packagers report that the trailing zeroes result in the calculated hash being
different. To restore compatibility with previous hash calculations and
signatures, change the reported size by excluding the trailing padding. This
should restore the calculation results for the case where only one initrd is
used.

This patch doesn't touch the stub, i.e. doesn't change behaviour for UKIs. The
seems fine, since we didn't change that recently, so any changes there would
break compatiblity. The measurement results for type#1 and type#2 entries are
generally going to be different anyway. ukify and systemd-measure are also out
of scope here, because they are for UKIs.

Fixes https://github.com/systemd/systemd/issues/35439.
The other changes to the way the initrd is constructed are kept, so hopefully
the original issue with booting in qemu is not recreated.

[1] https://bugzilla.suse.com/show_bug.cgi?id=1233752

My simple test: I'm booting a QEMU VM with systemd-boot and a type#1 entry.
With old systemd-boot:
$ sudo systemd-pcrlock log | grep 'kernel-initrd.*event-tag'
  9 █ kernel-initrd  event-tag  - a337a8321bf81de5c53a842843e8f9a926f73a676e5620ff76df94d1c66bc931 F   - Linux: kernel command line
  9 █ kernel-initrd  event-tag  - aec1aee5358bde36f5498f2dc243dec2b103f81242de57b887a11f53677f1272 F   - Linux: initrd
With updated systemd-boot:
$ sudo systemd-pcrlock log | grep 'kernel-initrd.*event-tag'
  9 █ kernel-initrd  event-tag  - a337a8321bf81de5c53a842843e8f9a926f73a676e5620ff76df94d1c66bc931 F   - Linux: kernel command line
  9 █ kernel-initrd  event-tag  - 3ccaa710304aef8734a20265ea7fd3dd67d5461c6b3309c6d30d5c7d2a3ae7f9 F   - Linux: initrd
This matches the initrd hash:
$ sudo sha256sum /efi//26f948d2082e4ae89f5a3af351b63149/6.12.0-rc4+/initrd-dracut
3ccaa710304aef8734a20265ea7fd3dd67d5461c6b3309c6d30d5c7d2a3ae7f9  /efi//26f948d2082e4ae89f5a3af351b63149/6.12.0-rc4+/initrd-dracut
2024-12-09 15:14:03 +01:00
Adrian Vovk
5a10a9a3bb sd-stub: Fixup typo & measurement order
A previous commit accidentally reversed the measurement order of the
confext initrds and sysext initrds via a minor typo. This commit fixes
the typo and restores the original measurement order

Follow-up: ac32323
2024-11-26 16:33:09 -05:00
Lennart Poettering
be6e599935 boot: make .hwids PE section more flexible to cover more than DT one day
The proposal in https://github.com/systemd/systemd/pull/35091 suggests
that there are going to be more resources sooner or later that shall be
embeddable in a UKI, but are specific to some machine. The .hwids logic
as it is implemented right now is conceptually flexible enough to cover
that too (as long as the system has SMBIOS and thus CHIDs). Hence, let's
prepare the ground for a future (that might possibly never come, but
let's keep the door open) where the section can be reused for this
purpose.

The patch is really dumb ultimately. it just changes the initial field
in the "Device" struct to carry not just the size of it (as before) but
also a type indicator, that is for now fixed to 1, indicating DT blobs.

This breaks compatibility, hence this should get merged before we do the
v257 release, so that this is done properly before the first release
with .hwids.
2024-11-15 15:40:43 +00:00
Lennart Poettering
9386bcc2da boot: explain the 4G quirks we apply to initrd memory allocations
Given how long it took to come to a conclusion of the discussions around
https://github.com/systemd/systemd/issues/35026, let's add a comment
that makes this easier to grok for the next time this comes up.

Follow-up for: 6e207b370e
2024-11-15 10:14:17 +00:00
andre4ik3
6e207b370e boot/stub: allocate pages for combined initrds below 4GiB only on x86 (#35149)
Outside of x86, some machines (e.g. Apple silicon, AMD Opteron A1100)
have physical memory mapped above 4GiB, meaning this allocation will
fail, causing the entire boot process to fail on these machines.

This commit makes it so that the below-4GB address space allocation
requirement is only set on x86 platforms, and not on other platforms
(that don't have the specific Linux x86 boot protocol), thereby fixing
boot on those that have no memory mapped below 4GiB in their address
space.

Tested on an Apple silicon M1 laptop and an AMD x86_64 desktop tower.

Fixes: #35026
2024-11-14 13:20:09 +09:00
Lennart Poettering
f2b4f19881 pe: use PE_SECTION_VECTOR_IS_SET() macro where appropriate 2024-11-12 23:45:15 +01:00
Lennart Poettering
557d9fd5d1 pe: remove unnecessary log message about DT/HWID
Fixes: #35100
2024-11-12 23:45:14 +01:00
Lennart Poettering
1991ffa912 efi: don't log if EFI RNG isn't ready
Apparently this happens IRL on some systems, let's handle this
gracefully and don't log.

Fixes: #35033
2024-11-12 23:44:59 +01:00
anonymix007
24677c6787 boot: Fix .dtbauto section number for error reporting 2024-11-07 22:52:29 +03:00
anonymix007
145479f4d0 boot: Fix overflow check for FDT_PROP in devicetree_get_compatible 2024-11-07 22:52:29 +03:00