Commit Graph
1000 Commits
Author SHA1 Message Date
Lennart Poettering b353d5eee9 bootctl,bootspec: make use of CHASE_PROHIBIT_SYMLINKS whenever we access the ESP/XBOOTLDR
Let's make use of the new flag whenever we access the ESP or XBOOTLDR.
The resources we make use of in these partitions can't possibly use
symlinks (because UEFI knows no symlink concept), and they are untrusted
territory, hence under no circumstances we should be tricked into
following symlinks that shouldn't be there in the first place.

Of course, you might argue thta ESP/XBOOTLDR are VFAT and thus don#t
know symlinks. But the thing is, they don#t have to be. Firmware can
support other file systems too, and people can use efifs to gain access
to arbitrary Linux file systems from EFI. Hence, let's better be safe
than sorry.
2022-11-13 17:46:34 +09:00
Zbigniew Jędrzejewski-Szmek d6b4d1c7c4 basic: move version() to build.h+c 2022-11-08 13:41:14 +01:00
Zbigniew Jędrzejewski-Szmek baa6a42d27 basic: create new basic/initrd-util.[ch] for initrd-related functions
I changed imports of util.h to initrd-util.h, or added an import of
initrd-util.h, to keep compilation working. It turns out that many files didn't
import util.h directly.

When viewing the patch, don't be confused by git rename detection logic:
a new .c file is added and two functions moved into it.
2022-11-08 13:41:13 +01:00
Lennart Poettering 2e6a0579cc measure: honour phases when signing 2022-10-31 16:52:00 +01:00
Lennart Poettering 28acd1e6c3 measure: banks and phases list are always non-empty
When parsing parameters, we populate these lists with defaults when
empty, hence we can rely that there's at least one bank and one phase
defined.
2022-10-31 16:51:12 +01:00
Jan Janssen dcebf1d87e boot: Mark some functions as static 2022-10-30 14:17:11 +01:00
Yu Watanabe bcf04e9b27 tree-wide: fix typo 2022-10-26 03:24:45 +09:00
Jan Janssen 09da51f8e9 boot: Rework shim image verification
This moves the shim security arch override to the new
ReinstallProtocolInterface based interface. This also has the benefit to
reduce the time window in which we have this override active and also
actually removes it, which was not previously done.

The shim hooks themselves are also modernized too. The upcalls should
really not be neccessary if shim is happy with the provided binary.
2022-10-17 14:49:11 +02:00
Jan Janssen 6731a102da stub: Allow loading unsigned kernel images 2022-10-17 14:48:28 +02:00
Jan Janssen 0e3c374e8c boot: Use proper security arch protocol names
This is how the Platform Intregration Specification defines these.
2022-10-17 14:47:42 +02:00
Jan Janssen dcde6ae165 boot: Remove unused parameters from pe_kernel_info
Only the compat entry address is used now. This also now only returns
the compat entry address. If the image is native we do not need to try
calling into the entry address again as we would already have done so
from StartImage (and failed).
2022-10-17 14:47:42 +02:00
Jan Janssen a529d8182e stub: Use LoadImage/StartImage to start the kernel
This is the proper way to start any EFI binary. The fact this even ever
worked was because the kernel does not have any PE relocations.

The only downside is that the embedded kernel image has to be signed and
trusted by the firmware under secure boot. A future commit will try to
deal with that.
2022-10-17 14:47:39 +02:00
Jan Janssen bfc075fa6b stub: Rename image parameter
This is really the parent image for the kernel that is to be run.
Renaming it as such prevents confusion with any image handles that are
about to be created.
2022-10-17 14:41:26 +02:00
Lennart Poettering 8d9295bbf5 pcrphase: fix --help text
We don't take a command, we just take a "word" which we'll extend into
PCR 11.
2022-10-17 12:39:33 +02:00
Lennart Poettering 047273e6e8 pcrphase: add two additional phases
This adds two more phases to the PCR boot phase logic: "sysinit" +
"final".

The "sysinit" one is placed between sysinit.target and basic.target.
It's good to have a milestone in this place, since this is after all
file systems/LUKS volumes are in place (which sooner or later should
result in measurements of their own) and before services are started
(where we should be able to rely on them to be complete).

This is particularly useful to make certain secrets available for
mounting secondary file systems, but making them unavailable later.

This breaks API in a way (as measurements during runtime will change),
but given that the pcrphase stuff wasn't realeased yet should be OK.
2022-10-17 12:09:43 +02:00
Jan Janssen d388f3d723 stub: Fix booting with old kernels
This fixes a regression introduced in e1636807 that removed setting this
value as it seemingly was not used by the kernel and would actively
break above 4G boots. But old kernels (4.18 in particular) will not boot
properly if it is not filled out by us.
The original issue was using the truncated value to then jump into the
kernel entry point, which we do not do anymore. So setting this value
again on newer kernels is fine.
2022-10-17 08:43:01 +02:00
Jan Janssen 1a9874905a boot: Always reconnect all drivers
Fixes: #23442
2022-10-12 13:36:22 +02:00
Gerd Hoffmann 5b3e33c26f boot: export reconnect()
Also give it a more descriptive name.
2022-10-12 13:36:22 +02:00
Jan Janssen 2985110b6f stub: Correctly handle multi node file paths
Fixes: #24955
2022-10-12 13:19:34 +02:00
Jan Janssen 616a80fe1a boot: Use device_path_to_str 2022-10-12 13:19:34 +02:00
Jan Janssen 3b3eb196a2 boot: Add device_path_to_str 2022-10-12 13:19:34 +02:00
Luca Boccassi da60182759 Merge pull request #24933 from keszybz/erradicate-strerror
Erradicate strerror
2022-10-11 21:47:38 +02:00
Zbigniew Jędrzejewski-Szmek 0b6a47957b tree-wide: drop () around the first argument of a ternary op
https://github.com/systemd/systemd/pull/24933#discussion_r991242789
2022-10-11 16:59:00 +02:00
Jan Janssen 7aa4762ce2 meson: Fix build with --optimization=plain
Note that -O0 is deliberately filtered out as we have to compile with at
least -O1 due to #24202.

Fixes: #24323
2022-10-09 22:15:11 +02:00
Jan Janssen 957dfcc96d stub: Remove unused function parameter 2022-09-29 10:30:37 +02:00
Yu Watanabe c5654483dc fuzz: tighten acceptable data size
Fixes oss-fuzz#51887 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=51887).
Fixes #24833.
2022-09-28 09:12:36 +02:00
Jan Janssen af4b8cef38 boot: Make efi_fnmatch non-backtracking 2022-09-25 14:26:00 +02:00
Jan Janssen ac37f132a1 fuzz: Add fuzzer for some efi string functions 2022-09-25 14:26:00 +02:00
Jan Janssen 4b8eb86360 fuzz: Introduce DO_NOT_OPTIMIZE
The compiler may decide computations like these are not doing anything
and decide to optimize them away. This would defeat the whole fuzzing
exercise. This macro will force the compiler to materialize the value
no matter what. It should be less prone to accidents compared to using
log functions, which would either slow things down or still optimize the
value away (or simply move it into the if branch the log macros create).

The benefit over assert_se would be that no requirement is made on the
value itself. If we are fine getting a string of any size (including
zero), an assert_se would either create a noisy compiler warning about
conditions that would alawys be met or yet again optimize the whole
thing away.
2022-09-25 14:26:00 +02:00
Jan Janssen e7508839af fuzz-bcd: Do not include bcd.c
This is not needed anymore, so do it the proper way now.
2022-09-25 14:26:00 +02:00
Yu Watanabe 3b51a183af tree-wide: fix typo 2022-09-24 10:43:58 +09:00
Lennart Poettering 6e19a7ce13 Merge pull request #24628 from medhefgo/boot-sections
boot: Try to detect overlapping PE sections
2022-09-23 15:45:28 +02:00
Lennart Poettering 1a9c67a98a measure: clarify we actually try to calculate for all four banks by default 2022-09-22 16:56:57 +02:00
Lennart Poettering a434e25f52 measure: make --public-key= optional if "sign" is called
We can derive the public key from the private key, so let's do that, to
make things a bit easier.
2022-09-22 16:55:56 +02:00
Lennart Poettering 6ca0016398 measure: allow pre-calculating PCR values for multiple boot phases 2022-09-22 16:54:48 +02:00
Lennart Poettering 708d752479 boot: add new pcrphase tool to measure barrier strings into PCR 11 2022-09-22 16:52:06 +02:00
Luca Boccassi e5a2977c9a Merge pull request #24620 from poettering/measure-tweaks
measure: some tweaks
2022-09-22 12:53:48 +01:00
Lennart Poettering 64650de778 stub: fix conditionalization of initrd assembly
We forgot to conditionalize this on pcrsig/pcrpkey too. So if you have
ne creds or sysext configured we actually wouldn't pass pcrsig/pcrpkey
along. Let's fix that.
2022-09-21 19:43:48 +02:00
Lennart Poettering 996dbf98e4 measure: separate out PE section options in --help text
Let's separate the PE section options in the --help text to make clearer
that they are about PE sections, and thus make things less confusing
regarding the cryptic names. Specifically, there's now a separate
section in the --help text that looks like this:

<snip>
UKI PE Section Options:                                         UKI PE Section
     --linux=PATH        Path Linux kernel image                → .linux
     --osrel=PATH        Path to os-release file                → .osrel
     --cmdline=PATH      Path to file with kernel command line  → .cmdline
     --initrd=PATH       Path to initrd image                   → .initrd
     --splash=PATH       Path to splash bitmap                  → .splash
     --dtb=PATH          Path to Devicetree file                → .dtb
     --pcrpkey=PATH      Path to public key for PCR signatures  → .pcrpkey
</snipe>

(The section title is underlined, like we usually do it)

I think separating this out, and organizing the section name in tabular
form emphasizes nicely where this switches get their name from and what
they mean.

Hopefully addresses concerns from
https://github.com/systemd/systemd/pull/24458#discussion_r967052720 in a
diferent way.

(Also dropped a hint regarding DER format for public key. it's simply
wrong, we use PEM like everyone else on Linux. Outside of Java land DER
isn't popular, so we don't need to mention it here in the --help text,
man page should be enough.)
2022-09-20 18:51:37 +02:00
Lennart Poettering 5dcb9c3ccd stub: typo fix in comment
https://github.com/systemd/systemd/pull/24458#discussion_r966941104
2022-09-20 18:40:39 +02:00
Jan Janssen ba2a105c2b stub: Always use LINUX_INITRD_MEDIA_GUID if available
The kernel PE image version can be used to detect support for this
feature, allowing us to prefer the generic code of the deprecated EFI
handover protocol.
2022-09-20 13:05:41 +02:00
Jan Janssen a3461db85f stub: Be explicit about EFI handover calling convention 2022-09-20 12:55:43 +02:00
Jan Janssen c4e2302ee6 stub: Remove unnecessary asm cli call
Apparently, this is not needed when red zones are disabled and we do
that.
2022-09-20 12:55:43 +02:00
Jan Janssen 09173c916c stub: Properly clean up pages on error 2022-09-20 12:55:39 +02:00
Jan Janssen 757d6c916d stub: Refuse operation if kernel lacks EFI handover support 2022-09-20 12:54:53 +02:00
Jan Janssen 6944c61163 stub: Refuse operating above 4G if not supported
We could try to relocate these but that is probably not needed. So far
we have not been bitten by this in the real world and kernels we boot
likely already support this anyway.
2022-09-20 12:54:53 +02:00
Jan Janssen d62c177756 stub: Provide a proper boot params page
The boot params passed to the kernel only has to be one page in size
and the size of the setup header has to be calculated as it depends on
the boot protocol version supported by the kernel.
2022-09-20 12:54:47 +02:00
Jan Janssen e163680774 stub: Fix above 4G boot
The kernel x86 boot protocol does not expect this value to be set when
using EFI handover protocol. If the stub is loaded above 4G we would
end up discarding the high bits, breaking boot.

Fixes: #24707
2022-09-20 12:45:07 +02:00
Jan Janssen 55b5daf9b2 boot: Change the way we provide builtins
Relying on symbol aliasing seems to be rather unreliable. Instead just
use some light #ifdefery.

Fixes: #24630
2022-09-20 12:43:48 +02:00
Lennart Poettering f92ebc86dd tpm2-util: make tpm2_pcr_bank_from_string() case-insensitive
This way we can use it directly in measure.c, and thus remove a bit of
redundant code.

OpenSSL prefers uppercasing the MD names, others don't hence let's be
lenient here.
2022-09-19 22:50:44 +09:00