Commit Graph
1413 Commits
Author SHA1 Message Date
David Tardon 92651a7a2d tree-wide: initialize fds with -EBADF 2023-02-23 09:48:54 +01:00
Jan Janssen 10e27f768b boot: Take advantage of packed device paths
Now that device path types are marked as packed we can safely cast and
access them. If we ever take the address of a member, we would get a
compiler warning.
2023-02-22 21:56:26 +01:00
Jan Janssen ea592abfc6 boot: Add GUID format helper macro 2023-02-22 21:56:20 +01:00
Jan Janssen 0b92662821 boot: Move more device path helpers to device-path-util.c
This also renames them to stay consistent with our naming style.
2023-02-22 21:54:11 +01:00
Jan Janssen d755ac6214 boot: Remove some device path helper macros
In gnu-efi/EDK2 device paths are not marked as packed and instead the
Length field is split into 2 bytes. Accessing those requires these
helper macros as device paths may be unaligned.

Since our own efi headers define device path structs as packed, we can
access these directly, making code much more readable.
2023-02-22 21:54:11 +01:00
Jan Janssen e6d7dc9ada boot: Split out device path functions
No code changes aside from renaming path_replace_hd() and making its
parameter take any device path node type.
2023-02-22 21:54:11 +01:00
Jan Janssen 8e760b3fcd boot: Move disk_get_part_uuid into part-discovery.c
Thematically, they are similar and disk.c is awfully small to warrant
the separation.
2023-02-22 21:54:11 +01:00
Daan De Meyer ad36d31ea5 efi-string: Add startswith8()
startswith() from string-util-fundamental.h is defined for sd_char
which is char16_t, so let's add an implementation for char as well.
2023-02-22 16:55:07 +01:00
Daan De Meyer bbef5a9617 efi-string: Fix strchr() null byte handling
strchr() should be able to search for the terminating null byte,
our implementation doesn't, let's fix that.
2023-02-22 16:55:07 +01:00
Yu Watanabe 4788f635e3 Merge pull request #26203 from medhefgo/meson
meson: Use dicts for test/fuzzer definitions
2023-02-22 10:27:16 +09:00
Jan Janssen 5fa3e628cd boot: Drop _harder suffix
Since there is no use of gnu-efi functions anymore, we don't need to
distinguish them by name.
2023-02-21 21:07:04 +01:00
Jan Janssen 3ceaa05d56 boot: Do not use errno.h/inttypes.h
These are provided by libc instead of the compiler and are not supposed
to be used in freestanding environments.
When cross-compiling with clang and the corresponding gcc
cross-toolchain is not around, clang may pick up the wrong header from
the host system.
2023-02-21 21:07:04 +01:00
Jan Janssen 024951fb22 stub: Fix unaligned read 2023-02-21 21:01:47 +01:00
Zbigniew Jędrzejewski-Szmek 377d36898c Merge pull request #26446 from medhefgo/efi-headers
boot: Provide our own EFI API headers
2023-02-21 20:59:33 +01:00
Zbigniew Jędrzejewski-Szmek 1eca770933 efi: drop executable-stack bit from .elf file
An rpminspect test in Fedora/RHEL is flagging our stub files as having an
executable stack. The check is correct:

$ readelf --wide --program-headers build/src/boot/efi/linuxx64.elf.stub | rg -i stack
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10

It seems to be just an omission in the linker script… None of the objects that
are linked into the stub are marked as requiring an executable stack:

$ readelf --wide --sections build/src/boot/efi/*.c.o \
  /usr/lib/gnuefi/x64/libgnuefi.a \
  /usr/lib/gnuefi/x64/libefi.a \
  /usr/lib/gcc/x86_64-redhat-linux/12/libgcc.a \
  | rg '.note.GNU-stack.*X'
(nothing)

On aarch64 we end up with a nonexecutable stack, but on ia32 and x64 we get one,
so this might be just a matter of defaults in the linker. It doesn't matter
greatly, but let's mark the stack as non-executable to avoid the warning.

Note: '-Wl,-z' is not needed, things work with just '-z'.
2023-02-21 20:51:47 +01:00
Lennart Poettering c56be2c294 bootctl: add new --print-root-device option
We already have this nice code in system that determines the block
device backing the root file system, but it's only used internally in
systemd-gpt-generator. Let's make this more accessible and expose it
directly in bootctl.

It doesn't fit immediately into the topic of bootctl, but I think it's
close enough and behaves very similar to the existing "bootctl
--print-boot-path" and "--print-esp-path" tools.

If --print-root-device (or -R) is specified once, will show the block device
backing the root fs, and if specified twice (probably easier: -RR) it
will show the whole block device that block device belongs to in case it
is a partition block device.

Suggested use:

        # cfdisk `bootctl -RR`

To get access to the partition table, behind the OS install, for
whatever it might be.
2023-02-21 18:19:38 +01:00
Jan Janssen 2ed35b2f3e meson: Use dicts for fuzzer definitions 2023-02-21 15:10:26 +01:00
Jan Janssen 822cd3ff25 meson: Use dicts for test definitions
Although this slightly more verbose it makes it much easier to reason
about. The code that produces the tests heavily benefits from this.

Test lists are also now sorted by test name.
2023-02-21 15:10:26 +01:00
Jan Janssen 5080a60a71 boot: Provide our own EFI API headers
We want to get away from gnu-efi and the only really usable source of
EFI headers would be EDK2, which is somewhat impractical to use and
quite large to require to be around just for some headers.

As a bonus point, the new headers are safe to be included in userspace
code.

This should not have any behavior changes as it is mostly changing
header includes. There are some renames to conform to standard names
and a few minor device path fixups as the struct is defined slightly
different.

Of note is that this removes usage of uchar.h and wchar.h as they are
not guaranteed to be available in a freestanding environment. Instead
efi.h will provide the needed types.
2023-02-21 14:46:02 +01:00
Jan Janssen a409607489 boot: Query EFI var size before fetching them 2023-02-21 14:44:53 +01:00
Jan Janssen b3e2557629 boot: Use C escape sequence for control chars
This makes things less magical by emphasizing that these are just
regular ascii/unicode chars.
2023-02-21 14:44:53 +01:00
Jan Janssen 65d40db7de boot: Drop use of efigpt.h 2023-02-21 14:44:48 +01:00
Zbigniew Jędrzejewski-Szmek 650a4a9565 efi/measure: adjust formatting 2023-02-20 13:38:32 +01:00
Zbigniew Jędrzejewski-Szmek bad6b4405c measure: wrap long lines and avoid one cast 2023-02-20 13:38:32 +01:00
Daan De Meyer a133d2c366 dissect-image: Return mount point fd if requested 2023-02-17 14:58:55 +01:00
Jan Janssen f92428eae5 boot: Fix assertion failure
The TPM code expects a description unless the PCR index indicates that
no measurements have to take place. The assert was preempting this
check from happening.

Fixes: #26428
2023-02-17 05:01:53 +09:00
Samanta Navarro 2d5ccb0818 bootctl: Fix debug messages
Remove duplicate KERNEL_INSTALL_MACHINE_ID from message and also
specify the correct origin of layout variable.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-02-16 16:37:02 +00:00
Mike Gilbert 7cd137e647 bootctl: avoid using __WORDSIZE macro
__WORDSIZE does not seem to be documented anywhere, and is probably
meant to be used internally by glibc headers.

In systemd, it was only being used in warning messages. We can avoid
using it by rewording the messages slightly.

Fixes a build error with musl libc.

Bug: https://bugs.gentoo.org/894430
2023-02-15 10:24:25 +09:00
Yu Watanabe 0b75493da0 tree-wide: fix typo and comment style update 2023-02-15 10:08:16 +09:00
Jan Janssen ec96dad2f4 boot: Ensure raise() is not dropped by LTO 2023-02-12 22:23:22 +01:00
Jan Janssen 5983306474 boot: Fix undefined reference to raise() on arm
This is just a workaround. Once we drop gnu-efi, the arm build system
for EFI binaries should be changed to use the arm-none-eabi toolchain,
which should not exhibit this behavior.
2023-02-09 21:55:40 +00:00
Daan De Meyer 77db9ef2ab boot: Make sure we take --root into account everywhere. 2023-02-09 14:46:17 +00:00
Daan De Meyer 3b42ffe590 bootctl: Add missing %m 2023-02-09 11:31:57 +00:00
Luca Boccassi 5b5aaf9a91 Merge pull request #26180 from ddstreet/tpm2_cleanup
Add struct tpm2_handle and use _cleanup_ instead of goto
2023-02-01 23:40:52 +00:00
Luca Boccassi e5cf396181 Merge pull request #26287 from medhefgo/mkosi-auto-enroll
ci: Test with secure boot enabled under mkosi
2023-02-01 21:51:04 +00:00
Dan Streetman 16e16b8c7b tpm2: add Tpm2Handle with automatic cleanup
This allows using _cleanup_ with the handles, which then allows removing the
use of goto in all functions that use the handles.
2023-02-01 12:52:08 -05:00
Dan Streetman 23e9ccc24a tpm2: use Tpm2Context* instead of ESYS_CONTEXT*
This is needed for later patches that use Tpm2Handle, which requires access
to the Tpm2Context.
2023-02-01 12:51:17 -05:00
Dan Streetman 68d084cee5 tpm2: use ref counter for Tpm2Context
This will be used by Tpm2Handle instances, which is added in later patches.

The refcounting allows the context to be retained until all Tpm2Handles have
been cleaned up, and the initial ref is released, before cleaning the context.
2023-02-01 12:51:17 -05:00
Dan Streetman bd860983a6 tpm2: rename struct tpm2_context to Tpm2Context
This aligns with systemd coding guidelines for struct naming
2023-02-01 12:51:17 -05:00
Dan Streetman 7bfe0a48d9 tpm2: rename tpm2 alg id<->string functions
The 'pcr_bank' functions operate on hash algs, and are not specific to the PCR
banks, while the 'primary_alg' functions operate on asymmetric algs, and are
not specific to primary keys.
2023-02-01 18:13:48 +01:00
Jan Janssen 1e8e7f4463 boot: Add if-safe mode for secure boot enrollment 2023-02-01 16:52:28 +01:00
Lennart Poettering 74e795ee55 id128: introduce ERRNO_IS_MACHINE_ID_UNSET() helper macro 2023-02-01 15:25:30 +01:00
Jan Janssen 2df8574af0 boot: Use aarch64 virtual counter
This should be used in VMs and should also yield the same value when
running on real devices. It is also what grub uses.

Fixes: #26224
2023-01-27 09:26:16 +01:00
Jan Janssen a083aed03f boot: Use unicode literals
No changes in behavior.
2023-01-25 15:24:10 +01:00
Jan Janssen 54d9ecc380 boot: Use unsigned for beep counting 2023-01-25 15:23:49 +01:00
Jan Janssen dede50a715 boot: Replace UINTN with size_t
No changes in behavior.
2023-01-25 15:22:41 +01:00
Yu Watanabe a0344b17dd bootctl-status: several follow-ups for unlink command
Follow-ups for 8702496bfb.

- add missing error cause in logging,
- add several missing assertions,
- drop an unnecessary initialization,
- make boot_config_find_in() return negative errno if nothing found,
- and several coding style fixlets.
2023-01-25 10:51:50 +00:00
Yu Watanabe 1b7586df97 bootctl-uki: several follow-ups for inspect_osrel()
Follow-ups for #26124 and #26158.

- use os_release_pretty_name(),
- constify the buffer passed to inspect_osrel(),
- propagate errors in inspect_osrele(), and ignore them in the caller
  side,
- and several coding style fixlets.
2023-01-25 10:51:38 +00:00
Zbigniew Jędrzejewski-Szmek 2f6c52b919 shared/efi-loader: fix compilation with !ENABLE_EFI, improve messages
When compiled without ENABLE_EFI, efi_stub_measured() was not defined, so
compilation would fail. But it's not enough to add a stub that returns
-EOPNOTSUPP. We call this function in various places and usually print the error
at warning or error level, so we'd print a confusing message. We also can't add
a stub that always returns 0, because then we'd print a message like "Kernel
stub did not measure", which would be confusing too. Adding special handling for
-EOPNOTSUPP in every caller is also unattractive. So instead efi_stub_measured()
is reworked to log the warning or error internally, and such logging is removed
from the callers, and a stub is added that logs a custom message.
2023-01-24 23:07:21 +00:00
Jan Janssen 4a7ee0a521 meson: Do not include headers in source lists
Meson+ninja+compiler do this for us and are better at it.

https://mesonbuild.com/FAQ.html#do-i-need-to-add-my-headers-to-the-sources-list-like-in-autotools
2023-01-24 22:04:03 +01:00