From: Ana Bobillo <[email protected]>
With TCG2 measured boot, efi_load_pe() measures each image into PCR 4
or 2. When the measurement finds no TPM, the image is refused. Any other
error is ignored, so an image whose hash cannot be computed, because
efi_image_parse() rejects it, or whose PCR could not be extended is
loaded and can be started without being measured. With the range
checks added to efi_image_parse() earlier in this series, more
malformed images take this path. Such an image runs with boot services
and can start the expected boot loader itself, which is measured as
usual, so the PCRs end up as for a good boot.
Mark an image whose measurement failed as not authenticated, as
efi_load_pe() does for an image that fails Secure Boot authentication,
so that LoadImage() returns EFI_SECURITY_VIOLATION and StartImage()
refuses to start it. A full event log is no error, as in EDK2's
DxeTpm2MeasureBootLib: the PCR has been extended all the same.
Fixes: 163a0d7e2cbd ("efi_loader: add PE/COFF image measurement")
Signed-off-by: Ana Bobillo <[email protected]>
---
Changes in v3:
- apply to main without Heinrich's "efi_loader: handling of missing
TPM in efi_load_pe()": the new check comes before the one for a
missing TPM, so that this patch applies with or without Heinrich's,
and his applies on top of it (Ilias)
lib/efi_loader/efi_image_loader.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/efi_loader/efi_image_loader.c
b/lib/efi_loader/efi_image_loader.c
index 67b83af0e8e..b14065fed6c 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -1151,6 +1151,16 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj
*handle,
#if IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)
/* Measure an PE/COFF image */
ret = tcg2_measure_pe_image(efi, efi_size, handle, loaded_image_info);
+ if (ret != EFI_SUCCESS && ret != EFI_SECURITY_VIOLATION &&
+ ret != EFI_VOLUME_FULL) {
+ /*
+ * The image cannot be hashed or the PCR cannot be extended.
+ * Do not start an image that has not been measured. A full
+ * event log is no error: the PCR has been extended all the
same.
+ */
+ log_err("PE image measurement failed\n");
+ handle->auth_status = EFI_IMAGE_AUTH_FAILED;
+ }
if (ret == EFI_SECURITY_VIOLATION) {
/*
* TCG2 Protocol is installed but no TPM device found,