Commit Graph
1223 Commits
Author SHA1 Message Date
Lennart Poettering 766c30a3b5 Merge pull request #27256 from medhefgo/boot-rdtsc
boot: Improve timer frequency detection
2023-04-18 10:38:15 +02:00
Yu Watanabe 1113e50796 tree-wide: replace __alignof__() with alignof()
Addresses https://github.com/systemd/systemd/pull/27254#discussion_r1165267046.
2023-04-14 14:39:06 +09:00
Jan Janssen 2a3ae5fae0 boot: Use CPUID to detect TSC frequency
Aside from being more accurate on CPUs that report the information this
is also orders of magnitude faster than sleeping for 1ms.
2023-04-13 15:39:32 +02:00
Jan Janssen 706fd67e4a boot: Rework timer frquency reading
This is in preparation for the next commit.
2023-04-13 15:39:14 +02:00
Jan Janssen 09614b35c0 boot: Use compiler intrinsic for TSC 2023-04-13 15:36:27 +02:00
Yu Watanabe 06e78680e3 image-policy: introduce parse_image_policy_argument() helper
Addresses
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1060130312,
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1067927293, and
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1067926416.

Follow-up for 84be0c710d.
2023-04-13 11:17:28 +02:00
Yu Watanabe 8e1d6003fb Merge pull request #27217 from yuwata/boot-entry-at
boot-entry: introduce _at() variant
2023-04-12 22:59:54 +09:00
Lennart Poettering 3af48a86d9 Merge pull request #25608 from poettering/dissect-moar
dissect: add dissection policies
2023-04-12 13:46:08 +02:00
Yu Watanabe 3b5fc5fb1b boot-entry: prioritize machine ID only when it is not randomly generated
Preparation for later commits. The parameter will be used in
kernel-install later.
2023-04-12 08:31:50 +09:00
Jan Janssen b87d6da447 boot: Fix alignment of long long inside structs on x86
On x86 EFI follows the windows ABI, which expects 8-byte aligned long
long. The x86 sysv ELF ABI expects them to be 8-byte aligned when used
alone, but 4-byte aligned when they appear inside of structs:

    struct S {
        int i;
        long long ll;
    };

    // _Static_assert(sizeof(struct S) == 12, "x86 sysv ABI");
    _Static_assert(sizeof(struct S) == 16, "EFI/MS ABI");

To get the behavior we need when building with sysv ELF ABI we need to
pass '-malign-double' to the compiler as done by EDK2.

This in turn will make ubsan unhappy as the stack may not be properly
aligned on entry, so we have to tell the compiler explicitly to re-align
the stack on entry to efi_main.

This fixes loading EFI drivers on x86 that were previously always
rejected as the EFI_LOADED_IMAGE_PROTOCOL had a wrong memory layout.

See also: https://github.com/rhboot/shim/pull/516
2023-04-11 17:09:18 +01:00
Yu Watanabe b98afb23bf kernel-image: make inspect_kernel() optionally take directory fd 2023-04-09 07:10:20 +02:00
Daan De Meyer 05f7052732 bootctl: Gracefully handle missing bootloader directory
When --graceful is specified, let's gracefully deal with a missing
bootloader directory.
2023-04-07 10:34:34 +02:00
Lennart Poettering 84be0c710d tree-wide: hook up image dissection policy logic everywhere 2023-04-05 20:45:30 +02:00
Zbigniew Jędrzejewski-Szmek 51214cf491 various: simplify calls to parse_boolean_argument()
parse_boolean_argument() returns the same information via both the output
argument and normal return.
2023-04-05 13:06:26 +08:00
Zbigniew Jędrzejewski-Szmek 9b9f6aa412 bootctl: clean up handling of files with no version information
get_file_version() would return:
- various negative errors if the file could not be accessed or if it was not a
  regular file
- 0/NULL if the file was too small
- -ESRCH or -EINVAL if the file did not contain the marker
- -ENOMEM or permissions errors
-  1 if the marker was found

bootctl status iterates over /EFI/{systemd,BOOT}/*.efi and checks if the files
contain a systemd-boot version tag. Resource or permission errors should be
fatal, but lack of version information should be silently ignored.

OTOH, when updating or installing bootloader files, the version is expected
to be present.

get_file_version() is changed to return -ESRCH if the version is unavailable,
and other errnos for permission or resource errors.

The logging is reworked to always display an error if encountered, but also
to log the status at debug level what the result of the version inquiry is.
This makes it figure out what is going on:
  /efi/EFI/systemd/systemd-bootx64.efi: EFI binary LoaderInfo marker: "systemd-boot 253-6.fc38"
  /efi/EFI/BOOT/BOOTfbx64.efi: EFI binary has no LoaderInfo marker.
  /efi/EFI/BOOT/BOOTIA32.EFI: EFI binary has no LoaderInfo marker.
  /efi/EFI/BOOT/BOOTX64.EFI: EFI binary LoaderInfo marker: "systemd-boot 253-6.fc38"

Replaces #27034.
Fixes https://github.com/NixOS/nixpkgs/issues/223579.
2023-03-30 20:52:05 +01:00
Yu Watanabe 9e43296fd2 bootctl: split-out entry token related definitions into boot-entry.[ch]
No functional change, just preparation for later commits.
These can be used in kernel-install later.

Note, unlike the our usual coding style, the arguments for
boot_entry_token_ensure() and parse_boot_entry_token_type() are
referenced, updated, and may freed, hence, always pass initialized
values. That's why they are not named as 'ret_xyz'.
2023-03-27 09:51:18 +02:00
Yu Watanabe 87dc8b0851 bootctl: enable colored logging 2023-03-25 12:38:11 +09:00
Daan De Meyer f461a28da7 chase-symlinks: Rename chase_symlinks() to chase()
Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
2023-03-24 13:43:51 +01:00
Kevin P. Fleming 06d104d58f bootctl: 'graceful' should ignore EFI variable failures
Suppress errors when creating/writing EFI variables during 'bootctl update' if
'--graceful' mode is active (as the documentation indicates).

Closes #26773.
2023-03-22 09:16:49 +01:00
Yu Watanabe 5689e161cf util: rename uki-util.[ch] -> kernel-image.[ch]
As the file contains functions not only for UKI.
2023-03-21 16:49:26 +09:00
Yu Watanabe fe3198df66 uki-util: rename KernelType -> KernelImageType
The name KernelType is slightly ambiguous. The type is about kernel
image. Let's rename the enum to clarify that.
2023-03-21 16:44:52 +09:00
Yu Watanabe de2c62e847 bootctl: fix wrong type comparison 2023-03-20 13:58:20 +09:00
Yu Watanabe 0bc2bcf4fe Merge pull request #26759 from medhefgo/boot-stack-protector
boot: Add support for stack protector/trapping math/ubsan
2023-03-18 15:07:45 +09:00
Yu Watanabe 16af02cd97 uki-util: move functions for inspecting kernel to uki-util.[ch] 2023-03-17 20:40:34 +09:00
Yu Watanabe c8eced395b bootctl: introduce inspect_kernel()
Then, now verb_kernel_identify() and verb_kernel_inspect() can share
most of the code.
2023-03-17 20:40:34 +09:00
Yu Watanabe 8102ff2e3d bootctl: introduce uki_read_pretty_name()
No functional change, just prepration for later commits.
2023-03-17 20:40:34 +09:00
Yu Watanabe 748b15c277 bootctl: find matching section in read_pe_section()
No functional change, just refactoring.
2023-03-17 20:40:34 +09:00
Yu Watanabe 03221e746d bootctl: return 0 instead of EXIT_SUCCESS 2023-03-17 20:40:34 +09:00
Yu Watanabe ab94d98b29 bootctl: move verb_kernel_identity()
No functional change, just for making beautify later diffs.
2023-03-17 20:40:34 +09:00
Jan Janssen 1e7ff4ba88 boot: Add undefined sanitizer support
Sadly, no stack traces, but this is better than nothing.
2023-03-17 10:39:39 +01:00
Jan Janssen 0b482b37f9 meson: Share more C flags 2023-03-17 10:39:32 +01:00
Jan Janssen f64f82aa8d boot: Add support for -ftrapv 2023-03-17 10:35:29 +01:00
Jan Janssen 48e1b2c250 boot: Add support for -fstack-protector 2023-03-17 10:35:29 +01:00
Jan Janssen a05f03225e boot: Detect nested assertions 2023-03-17 10:35:29 +01:00
Daan De Meyer f5abe8f957 Merge pull request #26784 from DaanDeMeyer/chase-fix
Allow creating files and directories with chase_symlinks_open() and further improvements
2023-03-15 15:51:47 +01:00
Daan De Meyer 39eb3ffaaa fs-util: Drop unlink_noerrno() 2023-03-15 13:27:20 +01:00
Jan Janssen ccde62954c stub: Remove overlapping PE section warning
Now that we always create PE images with a non-zero image base we cannot
run into this issue anymore. Any tool that still uses the old hard-coded
section offsets will end up creating bad images with sections below the
image base. objcopy will warn about this and any PE loader will simply
refuse to load such an image. Meanwhile updated tools do not use
hard-coded offsets anymore.
2023-03-15 00:24:17 +00:00
Daan De Meyer 06344330a1 chase-symlinks: Remove unused ret_fd arguments 2023-03-14 13:46:58 +01:00
Yu Watanabe 5654a4f9c5 sd-boot: fix incompatible type
Fixes the following build error:
```
../src/boot/efi/vmm.c: In function ‘get_smbios_table’:
../src/boot/efi/vmm.c:217:24: error: incompatible types when returning type ‘_Bool’ but ‘const SmbiosHeader *’ was expected
  217 |                 return false;
      |                        ^~~~~
```
2023-03-12 19:49:16 +09:00
Yu Watanabe c9501b03cd Merge pull request #26641 from medhefgo/boot-elf2efi
boot: Drop gnu-efi / Add elf2efi.py
2023-03-11 17:15:01 +09:00
Morten Linderud 6dadf31d61 src: Fixup copy-paste error for terminal_urlify_man
Signed-off-by: Morten Linderud <morten@linderud.pw>
2023-03-10 20:21:30 +01:00
Jan Janssen 2c7c68e4e4 meson: Use static library for EFI tests
This also moves them so that fuzz builds do not need pyelftools around.
2023-03-10 11:41:08 +01:00
Jan Janssen 5d5525245b boot: Fix unused function warning 2023-03-10 11:41:08 +01:00
Jan Janssen 31ffb6b183 boot: Add RISCV32 and LoongArch support
This is completely untested, but should work in theory, as it's just
adding a couple defines according to the specs.
2023-03-10 11:41:08 +01:00
Jan Janssen c4ad9b23ca boot: Fix debug experience 2023-03-10 11:41:08 +01:00
Jan Janssen 2afeaf1675 boot: Bring back bootloader builds
This adds back sd-boot builds by using meson compile targets directly.
We can do this now, because userspace binaries use the special
dependency that allows us to easily separate flags, so that we don't
pass anything to EFI builds that shouldn't be passed.

Additionally, we pass a bunch of flags to hopefully disable/override any
distro provided flags that should not be used for EFI binaries.

Fixes: #12275
2023-03-10 11:41:08 +01:00
Jan Janssen dfca5587cf tree-wide: Drop gnu-efi
This drops all mentions of gnu-efi and its manual build machinery. A
future commit will bring bootloader builds back. A new bootloader meson
option is now used to control whether to build sd-boot and its userspace
tooling.
2023-03-10 11:41:03 +01:00
Dan Streetman c69bd0abdb tpm2: add/rename functions to manage pcr selections
This renames some functions to match other to/from_string() naming,
and allows better management of TPML_PCR_SELECTION and TPMS_PCR_SELECTION
structs.
2023-03-09 10:46:19 -05:00
Gerd Hoffmann 78088b8f43 bootctl: tweak DOS header magic check
Read the magic first, try reading the full DOS exe header only in case
the magic check succeeds.

This avoids throwing an header read error on small dummy files as used
by test-kernel-install.
2023-03-07 08:14:46 +01:00
Zbigniew Jędrzejewski-Szmek efcde781de meson: adjust for removal of gnu-efi compat
gnu-efi-3.0.11-13.fc39 in Fedora dropped the old include paths.
2023-03-05 19:11:58 +00:00