From cad105442d15344e39466c02d8ffe7daaff92901 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Jun 2021 16:34:34 +0200 Subject: [PATCH 1/2] cryptsetup: if TPM2 support is not compiled in, fallback to non-TPM2 mode gracefully Fixes: #19177 --- src/cryptsetup/cryptsetup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 28ac78cd37..ebd59ca68c 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -1070,6 +1070,8 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( &decrypted_key, &decrypted_key_size); if (r >= 0) break; + if (ERRNO_IS_NOT_SUPPORTED(r)) /* TPM2 support not compiled in? */ + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 support not available, falling back to traditional unlocking."); if (r != -EAGAIN) /* EAGAIN means: no tpm2 chip found */ return r; } else { @@ -1100,6 +1102,8 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( found_some ? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking." : "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking."); + if (ERRNO_IS_NOT_SUPPORTED(r)) /* TPM2 support not compiled in? */ + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), "TPM2 support not available, falling back to traditional unlocking."); if (r < 0) return r; From 71b25deae3fee6e16941ddc4055b443d449f62a8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Jun 2021 16:35:13 +0200 Subject: [PATCH 2/2] cryptsetup: don't bother waiting for TPM2 devices if we are on EFI and EFI says there is no TPM2 device Note that this means EFI-systems with a manually added TPM device won't be supported automatically, but given that the TPM2 trust model kinda requires firmware support I doubt it matters supporting this. And in all other cases it speeds things up a bit. --- src/cryptsetup/cryptsetup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index ebd59ca68c..dcaedac53e 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -17,6 +17,7 @@ #include "cryptsetup-tpm2.h" #include "cryptsetup-util.h" #include "device-util.h" +#include "efi-loader.h" #include "escape.h" #include "fileio.h" #include "fs-util.h" @@ -1136,6 +1137,10 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2( assert(!event); + if (is_efi_boot() && !efi_has_tpm2()) + return log_notice_errno(SYNTHETIC_ERRNO(EAGAIN), + "No TPM2 hardware discovered and EFI bios indicates no support for it either, assuming TPM2-less system, falling back to traditional unocking."); + r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m");