Commit Graph
1413 Commits
Author SHA1 Message Date
Jan Janssen fb90100cf0 boot: Unify idx type handling
This replaces several inconsistent use of types and unsound
signed comparisons.
The added max entry count is just for paranoia. Anyone with that
many boot entries deserves a medal.
2022-01-03 10:41:45 +01:00
Jan Janssen 159636cf74 boot: Convert goto into loop 2022-01-03 10:20:23 +01:00
Jan Janssen 0b2281a209 boot: Rename cleanup functions 2022-01-03 10:15:24 +01:00
Jan Janssen 75747c8a39 boot: Use objcopy to align sections
Not aligning these can create gaps in the section table. Some
firmware does not handle this nicely resulting in secure boot
signature fails.
Using objcopy ensures that any new sections in the future will be
properly aligned.

Fixes: #21956
2022-01-02 19:58:56 +01:00
Yu Watanabe 3c80c7bacf Merge pull request #21928 from medhefgo/boot-meson
meson: Boot
2022-01-02 23:40:46 +09:00
Jan Janssen 2f2b072267 meson: Get objcopy location from compiler 2022-01-02 10:18:26 +01:00
Jan Janssen 52adf0e91e meson: Remove efi-cc option
Changing the efi compiler this way doesn't really work. The gnu-efi
header checks as well as supported compiler flag checks use the
regular cc that meson detects. Changing the compiler this way will
end up with bad compiler flags. For the very same reason, this does
not work with a cross-compiler without going through proper meson
cross-compilation steps either.

The proper way to build systemd-boot with a different compiler is to
use a different build folder and then just use the proper ninja build
target to only build the bootloader/stub.
2022-01-02 10:18:26 +01:00
Jan Janssen aa1d0f2587 boot: Introduce helper macros for offset checking
This fixes a subtle sizeof overflow on 32bit machines.
2021-12-29 14:39:54 +01:00
Jan Janssen 1cadb35fd6 boot: Reject unaligned data
The data seems to be properly aligned in real BCD stores, so it
should be fine to just reject bad ones.

Fixes: #21917
2021-12-29 14:39:54 +01:00
Jan Janssen 77fcf28cb8 boot: Build BCD parser only on arches supported by Windows 2021-12-29 14:39:54 +01:00
Evgeny Vereshchagin 4b65fc8725 tests: add fuzz-bcd 2021-12-29 10:39:06 +00:00
ksa678491784 5204355861 stub: Do not assume having DeviceHandle 2021-12-29 11:59:57 +09:00
Jan Janssen 2198a77391 boot: Fix name length comparison 2021-12-27 22:49:02 +01:00
Jan Janssen c3c5b93a0c boot: Fix off-by-one offset sanity checks 2021-12-27 22:46:40 +01:00
Jan Janssen fab8275646 boot: Fix off-by-one NUL-termination 2021-12-27 22:41:50 +01:00
Yu Watanabe 3e7bf8535f tree-wide: fix typo 2021-12-25 18:32:22 +09:00
Zbigniew Jędrzejewski-Szmek e4e44a0107 meson: report SBAT settings 2021-12-23 20:06:17 +01:00
Zbigniew Jędrzejewski-Szmek 3f871f1205 meson: move efi summary() section to src/boot/efi
This way we can add the entries more naturally in the same place where
they are defined.
2021-12-23 13:52:33 +01:00
Zbigniew Jędrzejewski-Szmek 65dcf9f9a0 meson: move efi file lists closer to where they are used
The goal is to have the detection of features and paths done first, and
then the build target constructions second.
2021-12-23 13:52:33 +01:00
Jan Janssen e628944b11 boot: Use correct handle to find TextInputEx protocol
LibLocateProtocol will return the protocol for the first device that
supports it. But it may not actually come from the ConIn device that
we want to use here.

This should be the root cause of what was previously considered just
broken firmware. If you ask the wrong device to return some key, of
course it will never provide one.

This changes the way we handle input yet again in light of this new
knowledge and because using the correct TextInputEx with fallback to
ConIn can actually create double input in some cases.

Since we are now confident that we get the right TextInputEx, we can
use that exclusively, only falling back to ConIn if the console input
device does not support the better interface (the spec is pretty clear
that it must support it, though).

Because some firmware is broken, we still need to provide a fallback
to the previously used TextInputEx thats overrides ConIn/ConInEx if
it is functional.
2021-12-23 12:39:48 +01:00
Yu Watanabe 8f7a0fcbec meson: fix typo 2021-12-23 17:01:55 +09:00
Jan Janssen 2ef28d054d boot: Use -fvisibility=hidden instead of -fwhole-program
It's functionally the same for sd-boot, but using visibilty
is generally preferred over whole-program.
2021-12-23 00:26:25 +09:00
Jan Janssen e67e6691e5 boot: Fix armhf build failure
Fixes: #21842
2021-12-21 16:34:51 +00:00
Zbigniew Jędrzejewski-Szmek 1ff493d5c1 bootctl: deprecate --make-machine-id-directory=auto
Now that kernel-install creates the machine-id directory, we don't need to do
this is 'bootctl install', and in fact it's better not to do this since it
might never be necessary. So let's change the default behaviour to 'no'.

I kept support for 'auto' to maintain backwards compatibility, even though the
default was changed. Previous behaviour can be requested by specifying
--make-machine-id-directory=auto.
2021-12-17 18:48:08 +01:00
Zbigniew Jędrzejewski-Szmek 47fb161e3a bootctl: write KERNEL_INSTALL_LAYOUT=bls and KERNEL_INSTALL_MACHINE_ID=…
This is a natural extension of d6bce6e224: if we are installing sd-boot, we
want to use the sd-boot layout, so let's write the appropriate
KERNEL_INSTALL_LAYOUT setting. Effectively, if we do 'booctl install',
kernel-install will not autodetect the layout anymore.

And 357376d0bb added support for KERNEL_INSTALL_MACHINE_ID. We need to support
it here too. We both read it, so that we create the right directories, and also
write it if it wasn't written yet and we created some directories using it, so
that kernel-install that is executed later knows the machine-id that matches
the directories we crated.

The code is changed in some places to fail if we can't figure out the current
status. When installing the boot loader it's probably better not to guess.
2021-12-17 18:47:53 +01:00
Yu Watanabe 616f51c16d boot: fix typo 2021-12-17 04:11:41 +09:00
Zbigniew Jędrzejewski-Szmek af3b864d76 Define FOREACH_DIRENT through FOREACH_DIRENT_ALL
As in the previous commit, 'de' is used as the iterator variable name.
2021-12-15 22:50:00 +01:00
Jan Janssen db7f5ab68f test: Add BCD unit test 2021-12-11 21:32:29 +01:00
Jan Janssen 986fd3ebc2 boot: Remove unused memmem_safe 2021-12-11 21:32:29 +01:00
Jan Janssen f7bc0fb35b boot: Add BCD store parser
This replaces the memmem-based approach of finding a suitable title
for the windows boot manager with one that actually parses the BCD
store. It's probably faster but more importantly, it's more correct.

The memmem approach may detect stale title strings that are still
in the file but unused due to the way registry hives are updated.
This approach also allows us to detect if the BCD store is multi-boot
so that we can fall back on the generic one instead.
2021-12-11 21:32:23 +01:00
Jan Janssen 7700e9ba15 boot: Make OFFSETOF lowercase
This is more in line with the userspace offsetof.
2021-12-11 20:50:03 +01:00
Jan Janssen 245e9d55ae boot: Add strncasecmpa helper function 2021-12-11 20:50:03 +01:00
Jan Janssen 3af5a8c613 meson: Fix gnu-efi detection for clang
The gnu-efi headers emit some warnings in clang when not compiled with
-ffreestanding. This is normally not an issue for has_header_symbol()
unless meson is run with CFLAGS="-Werror". Note that this differs
from the --werror option, which does not get passed to clang.

Work around this by adding some compile args to the has_header_symbol()
invocation.
2021-12-12 04:31:41 +09:00
Zbigniew Jędrzejewski-Szmek 881ab17ef7 Merge pull request #21570 from AdrianVovk/stub-global-creds
stub: Load credentials from \loader\credentials\*.cred
2021-12-11 15:59:10 +01:00
Jan Janssen 1ad2c76d5d meson: Auto detect efi-ld 2021-12-11 11:29:30 +01:00
Adrian Vovk f3b6f33387 stub: Load credentials from \loader\credentials\*.cred
Some types of credentials that a user would want to pass
into the initrd do not depend on the specific kernel/initrd
version. For instance, this can include SSH keys, rootfs
encryption keys, dm-integrity keys, and so on. This
introduces a directory where such credentials can be placed
so that any kernel image will load them
2021-12-10 15:56:33 -05:00
Дамјан Георгиевски 12caf72716 bootctl: optionally install .signed efi file
if /usr/lib/systemd/boot/efi/systemd-bootx64.efi.signed exists
install that instead of /usr/lib/systemd/boot/efi/systemd-bootx64.efi

the idea is that SecureBoot tooling can create the efi.signed file
whenever /usr/lib/systemd/boot/efi/systemd-bootx64.efi from the package
is updated.
2021-12-08 22:21:34 +01:00
Adrian Vovk bf3f4d16d6 stub: Properly null-terminate filenames in pack_cpio_one
Previously, mangle_filename would write the null terminator, but
then wouldn't increment the pointer. Thus, the pad4 call that comes
immediately after mangle_filename would trample over the null
terminator that mangle_filename wrote. Since the padding is all
0s, this happened to work for the filenames it was tested for

However, in some cases, this would cause the pointer to be a different
position than predicted. Basically, the predicted size would be one
byte bigger than the actual size (the missing null terminator). Usually,
this disappeared into the alignment padding at the end of the buffer,
but if the buffer was already unexpectedly aligned (b/c it was a byte
shorter than expected), this would cause assertion failures.

Also, the c_namesize field in the cpio header was incorrect. It
didn't include the null terminator, as required by the spec.
2021-12-08 13:57:01 -05:00
Zbigniew Jędrzejewski-Szmek 3944ef20f5 Merge pull request #21264 from medhefgo/boot-lto
sd-boot: LTO support
2021-12-07 12:58:59 +01:00
Zbigniew Jędrzejewski-Szmek ed0e6f0f71 Merge pull request #21307 from medhefgo/boot-alloc
sd-boot: Non-failing allocators
2021-12-07 08:20:07 +01:00
Yu Watanabe a783421498 tree-wide: fix typo 2021-12-02 00:51:02 +09:00
Yu Watanabe a6f44d610c tree-wide: fix typo 2021-11-30 12:30:07 +00:00
Jan Janssen 0289441e09 sd-boot: Fix assert failure in random-seed.c
Fixes: #21556
2021-11-30 03:10:03 +09:00
Jan Janssen 0a15a824d2 sd-boot: Use non-failing allocators everywhere else 2021-11-29 16:20:45 +01:00
Jan Janssen ccfbdbdcab sd-boot: Simplify path creation 2021-11-29 16:20:45 +01:00
Jan Janssen 4f94341504 sd-boot: Make stra_to_path/stra_to_str non-failing 2021-11-29 16:20:45 +01:00
Jan Janssen da76f890aa sd-boot: Use non-failing allocators in boot.c 2021-11-29 16:20:45 +01:00
Jan Janssen 484ddd2926 sd-boot: Add non-failing allocators 2021-11-29 16:20:32 +01:00
Jan Janssen fd86250c1e sd-boot: Always add TextInputEx to wait queue if available 2021-11-29 14:42:18 +01:00
Jan Janssen b848b7e166 sd-boot: Add LTO support 2021-11-29 14:41:46 +01:00