diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-10-17 14:50:56 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-17 09:42:16 +0100 |
commit | 6c51b49ce0892ff923233a6031add4877100f5b0 (patch) | |
tree | 454025e5aa2a5bf4dd3d4461d91f1e007e87eb50 /src/cryptsetup | |
parent | 04959faa632272a8fc9cdac3121b2e4af721c1b6 (diff) | |
download | systemd-6c51b49ce0892ff923233a6031add4877100f5b0.tar.gz |
tpm2: add common helper for checking if we are running on UKI with TPM measurements
Let's introduce a common implementation of a function that checks
whether we are booted on a kernel with systemd-stub that has TPM PCR
measurements enabled. Do our own userspace measurements only if we
detect that.
PCRs are scarce and most likely there are projects which already make
use of them in other ways. Hence, instead of blindly stepping into their
territory let's conditionalize things so that people have to explicitly
buy into our PCR assignments before we start measuring things into them.
Specifically bind everything to an UKI that reported measurements.
This was previously already implemented in systemd-pcrphase, but with
this change we expand this to all tools that process PCR measurement
settings.
The env var to override the check is renamed to SYSTEMD_FORCE_MEASURE,
to make it more generic (since we'll use it at multiple places now).
This is not a compat break, since the original env var for that was not
included in any stable release yet.
Diffstat (limited to 'src/cryptsetup')
-rw-r--r-- | src/cryptsetup/cryptsetup.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 5efce63a38..2c9d416734 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -19,6 +19,7 @@ #include "cryptsetup-util.h" #include "device-util.h" #include "efi-api.h" +#include "efi-loader.h" #include "env-util.h" #include "escape.h" #include "fileio.h" @@ -827,6 +828,14 @@ static int measure_volume_key( return 0; } + r = efi_stub_measured(); + if (r < 0) + return log_warning_errno(r, "Failed to detect if we are running on a kernel image with TPM measurement enabled: %m"); + if (r == 0) { + log_debug("Kernel stub did not measure kernel image into the expected PCR, skipping userspace measurement, too."); + return 0; + } + #if HAVE_TPM2 r = dlopen_tpm2(); if (r < 0) |