Commit Graph
1413 Commits
Author SHA1 Message Date
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
Yu Watanabe e330f97a89 tree-wide: drop unused reference to DecryptedImage 2022-09-18 23:47:20 +09:00
Lennart Poettering f578c659c4 measure: rename measure_pcr() to measure_kernel()
Let's say what we actually measure, not what into (which is obvious
anyway).

This is generally more descriptive, but also good for later work that
allows measuring the boot phase too.
2022-09-18 07:27:00 +09:00
Yu Watanabe 6f2d367e49 Merge pull request #24272 from dtardon/asserts
Use ASSERT_PTR more
2022-09-13 21:08:10 +09:00
Yu Watanabe 63d18b6cd0 boot: fix missing initialization
Fixes CID#1497847.
2022-09-13 21:06:05 +09:00
David Tardon 995340074e tree-wide: use ASSERT_PTR more 2022-09-13 08:13:27 +02:00
Jan Janssen fa2eebc7a3 boot: Try to detect overlapping PE sections
This should help finding the cause of boot failures because of badly
assembled unified kernel images.
2022-09-10 09:02:35 +02:00
Jan Janssen c01bf79432 boot: Be more explicit where to look for sections
It only really makes sense to fetch the location from either one of
these fields, depending on whether we are looking at an in-memory
(relocated) or a file PE image.
2022-09-10 08:24:41 +02:00
Lennart Poettering 23002b45b1 stub: pass .pcrsig and .pcrpkey PE sections as cpio into invoked kernel
Pick up the two new sections in sd-stub and pass them as initrds into
the booted kernels, where they'll show up as
/.extra/tpm2-pcr-signature.json and /.extra/tpm2-pcr-public-key.pem in
the initrd file system.

The initrd is then supposed to pick these files up from there and save
them at a place that will survive into the host OS.
2022-09-09 11:30:04 +02:00
Lennart Poettering df7ee6f8b0 stub: add new special PE sections ".pcrsig" and ".pcrpkey" in unified kernels
These aren't wired up yet to do anything useful. For now we just define
them.

This sections are supposed to carry a signature for expected
measurements on PCR 11 if this kernel is booted, in the JSON format
"systemd-measure sign" generates, and the public key used for the
signature.

The idea is to embedd the signature and the public key in unified
kernels and making them available to userspace, so that userspace can
easily access them and enroll (for which the public key is needed) or
unlock (for which the PCR signature is needed) LUKS2 volumes and
credentials that are bound to the currently used kernel version stream.

Why put these files in PE sections rather than just into simple files in
the initrd or into the host fs?

The signature cannot be in the initrd, since it is after all covering
the initrd, and thus the initrd as input for the calculation cannot
carry the result of the calculation. Putting the signature onto the root
fs sucks too, since we typically want to unlock the root fs with it,
hence it would be inaccessible for it's primary purpose then.

The public key could be in the initrd or in the root fs, there's no
technical restriction for that. However, I still think it's a good idea
to put it in a PE section as well, because this means the piece of code
that attaches the signature can also attach the public key easily in one
step, which is nice since it allows separating the roles of the
kernel/initrd/root fs builder, and the role of the signer, and the
former doesn't have to have knowledge about what the latter is going to
add to the image.

Note that the signature section is excluded from the TPM measurements
sd-stub does about its resource sections, since – as mentioned – it's
the expected output of the signing operation whose input are the
measurements, hence it cannot also be input to them. The public key
section is included in the measurements however.
2022-09-09 11:28:38 +02:00
Lennart Poettering e139565b01 cpio: add helper for packing cpios of literally specified data blobs
Let's add simple helpers for passing data blobs from the stub into the
booted kernel as initrds that are generated on-the-fly.

(Note used yet, a later commit will make use of this)
2022-09-09 11:27:08 +02:00
Frantisek Sumsal 8432b0cd20 Merge pull request #24351 from poettering/pcr-sign
support for signed TPM2 PCR policies in cryptsetup/cryptenrolls/credentials
2022-09-08 19:07:04 +00:00
Lennart Poettering d56f77e17f measure: print a helpful message if TPM2 PCR sysfs attributes are missing
Prompted by:

https://github.com/systemd/systemd/pull/24351#pullrequestreview-1100418585
2022-09-08 19:46:54 +02:00
Lennart Poettering cdaaa62ca1 measure: add 'sign' verb 2022-09-08 16:27:07 +02:00
Jan Janssen 97f077df05 boot: Avoid magic values in timeout EFI vars 2022-09-07 12:55:55 +02:00
Jan Janssen 28fda21c85 boot: Use proper scan codes
This arg expects scan codes and it can be very confusing to find a key
conflict when trying to add a F3 button when there are no F3 keycodes
seemingly in use. CHAR_CARRIAGE_RETURN and SCAN_F3 use the same value,
so no changes in behavior.
2022-09-07 12:55:55 +02:00
Jan Janssen 230f78206a boot: Accept Ctrl+Del for deleting words 2022-09-07 12:55:55 +02:00
Jan Janssen d17d0e6770 boot: Correctly handle shift keys 2022-09-07 12:55:55 +02:00
Jan Janssen 0cf5f816f2 boot: Refuse GPT with invalid entry size
SizeOfPartitionEntry must be a multiple of 128 * 2^n.
2022-09-07 12:55:49 +02:00
Jan Janssen 71c628d426 boot: Fix device path unaligned access 2022-09-07 12:51:16 +02:00
Jan Janssen 515581d66a boot: Use mempcpy 2022-09-07 12:51:16 +02:00
Jan Janssen aa23f91ed6 boot: Add mempcpy 2022-09-07 12:51:10 +02:00
Jan Janssen c0f86d66f3 tree-wide: Use correct format specifiers
gcc will complain about all these with -Wformat-signedness.
2022-08-30 12:03:28 +02:00
Lennart Poettering 5eb1d8561c cpio: don't claim we measured anything if we weren't even asked
This is a bugfix.

Follow-up for 599fe002a1
2022-08-26 13:08:32 +02:00
Lennart Poettering 71611f2b56 cpio: split out cpio TPM measurement logic from pack_cpio()
No code change, just some refactoring, so that we can reuse the
measurement logic later elsewhere.
2022-08-26 13:08:32 +02:00
Luca Boccassi 5e98346220 Merge pull request #24254 from medhefgo/mold
ci: Add mold to build tests
2022-08-23 19:33:47 +01:00
Luca Boccassi 4a515c5bd6 Merge pull request #24396 from poettering/no-more-dirname
stop using dirname()/dirname_malloc()
2022-08-23 19:32:52 +01:00
Lennart Poettering 3a21f51c58 measure: fix minor memory leak
When using --current switch, copy in current hash, don't just reassign
buffers forgetting about the old.

While we are at it, allocate the local copy buffer later, in
measure_pcr() as we won#t need it in the --current case.
2022-08-23 19:31:58 +01:00
Lennart Poettering c06103be64 bless-boot: remove a bunch of 'else' 2022-08-23 15:10:15 +02:00
Lennart Poettering 45519d13a4 tree-wide: port things dirname_malloc() → path_extract_directory() 2022-08-23 15:10:15 +02:00
Jan Janssen 4fb6506deb meson: Downgrade efi-ld warning
The warning isn't that serious and mostly there to inform the user that
lld/mold cannot build efi binaries. It is also better to build test with
fatal meson warnings.
2022-08-23 10:26:02 +02:00
Lennart Poettering 127b72da2b measure: add --current switch for "systemd-measure calculate"
This allows allows shortcutting measurements of the specified files and
use the information from /sys/ instead.

This is not too useful on its own given that "systemd-measure status"
already exists which displays the current, relevant PCR values. The main
difference is how "complete" the information is. "status" will detect if
the measurements make any sense, and show more than PCR 11. "calculate
--current" otoh only reads PCR 11 and uses that, and that's really it.

This is mainly preparation for later work to add PCR signing to the
tool, where usually it makes most sense to sign prepared kernel images,
but for testing it's really useful to shortcut signing to the current
PCR values instead
2022-08-22 19:17:18 +01:00
Lennart Poettering 3730dc5d5b bootctl: port some more code over to chase_symlinks() from prefix_roota()
This is far from complete, but let's start moving this way.
2022-08-22 14:07:45 +02:00
Lennart Poettering 6564591cc3 measure: store bank name in PcrState structure
Let's not query/strdup()ascii_strlower() it all the time, but just cache
it once and use it.
2022-08-20 09:01:31 +09:00
Lennart Poettering c06b6d46fd measure: add json output 2022-08-19 23:26:09 +02:00
Lennart Poettering 1dad9cd766 Merge pull request #24362 from poettering/sha256-tweaks
some tweaks to the sha256 implementation
2022-08-19 16:33:35 +02:00
Rene Hollander d9bdb29bf5 Add --efi-boot-option-description argument to bootctl to control the name of the boot
entry.

By default an entry named "Linux Boot Manager" is created (which is the
previous behavior). With the flag the name of the entry can be
controlled, which is useful when installing systemd-boot to multiple ESP
partitions and having uniquely named entries.

Fixes #17044.
2022-08-19 14:55:31 +02:00
Lennart Poettering 558d96240b sha256: add sha256_direct()/SHA256_DIRECT() helpers 2022-08-19 12:53:04 +02:00