U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ana Bobillo <anabobillo3@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH 08/10] efi_loader: do not load an image that cannot be measured
Date: Fri, 30 Oct 2026 06:14:22 +0000	[thread overview]
Message-ID: <be672b54-42c4-48fa-a7ad-994a7ab47ea7@gmail.com> (raw)
In-Reply-To: <633dddd6-ee22-4cd6-a8b6-cb7df0650fae@gmail.com>

From: Ana Bobillo <anabobillo3@gmail.com>

With TCG2 measured boot, efi_load_pe() measures each image into PCR 4
or 2, but it gives up only when the measurement reports that no TPM was
found. 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.

As EDK2's DxeTpm2MeasureBootLib does, refuse to load an image whose
measurement failed: free the memory allocated for it, which the error
path leaked so far, and return EFI_ACCESS_DENIED, so that LoadImage()
returns no image handle. A full event log is no error, as there: the
PCR is extended all the same.

Fixes: 163a0d7e2cbd ("efi_loader: add PE/COFF image measurement")
Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
---
 lib/efi_loader/efi_image_loader.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
index c4f64f102e8..c33b693c4ff 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -1166,12 +1166,22 @@ 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_SECURITY_VIOLATION) {
-		/*
-		 * TCG2 Protocol is installed but no TPM device found,
-		 * this is not expected.
-		 */
-		log_err("PE image measurement failed, no tpm device found\n");
+	/*
+	 * Do not load an image that could not be measured. A full event log
+	 * is no error: the PCR has been extended all the same.
+	 */
+	if (ret != EFI_SUCCESS && ret != EFI_VOLUME_FULL) {
+		if (ret == EFI_SECURITY_VIOLATION)
+			/*
+			 * TCG2 Protocol is installed but no TPM device found,
+			 * this is not expected.
+			 */
+			log_err("PE image measurement failed, no tpm device found\n");
+		else
+			log_err("PE image measurement failed\n");
+		efi_free_pages((uintptr_t)efi_reloc,
+			       (virt_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT);
+		ret = EFI_ACCESS_DENIED;
 		goto err;
 	}
 

  parent reply	other threads:[~2026-10-30  6:14 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30  6:13 [PATCH 00/10] efi_loader: check PE images before using them Ana Bobillo
2026-10-30  6:13 ` [PATCH 01/10] efi_loader: check the NT header size in efi_check_pe() Ana Bobillo
2026-10-30  7:23   ` Ilias Apalodimas
2026-10-30 11:15   ` Heinrich Schuchardt
2026-10-30 11:40     ` Ana Bobillo
2026-10-30  6:13 ` [PATCH 02/10] efi_loader: check the PE image ranges in efi_image_parse() Ana Bobillo
2026-10-30 12:14   ` Heinrich Schuchardt
2026-10-30 12:49     ` Ana Bobillo
2026-10-30  6:13 ` [PATCH 03/10] efi_loader: reject a PE section whose end wraps around Ana Bobillo
2026-10-30  7:41   ` Ilias Apalodimas
2026-10-30 12:35   ` Heinrich Schuchardt
2026-10-30 12:49     ` Ana Bobillo
2026-10-30  6:14 ` [PATCH 04/10] efi_loader: check PE section raw data against the image size Ana Bobillo
2026-10-30 12:45   ` Heinrich Schuchardt
2026-10-30 12:51     ` Ana Bobillo
2026-10-30  6:14 ` [PATCH 05/10] efi_loader: check that the PE headers fit into the loaded image Ana Bobillo
2026-10-30 13:09   ` Heinrich Schuchardt
2026-10-30 14:05     ` Ana Bobillo
2026-10-30  6:14 ` [PATCH 06/10] efi_loader: check the relocation table against the image size Ana Bobillo
2026-10-30  6:14 ` [PATCH 07/10] efi_loader: check certificate lengths in efi_image_authenticate() Ana Bobillo
2026-10-30  6:14 ` Ana Bobillo [this message]
2026-10-30  7:22   ` [PATCH 08/10] efi_loader: do not load an image that cannot be measured Ilias Apalodimas
2026-10-30  7:54     ` Ana Bobillo
2026-10-30  9:23       ` Ilias Apalodimas
2026-10-30 10:04         ` Ana Bobillo
2026-10-30  6:14 ` [PATCH 09/10] test: lib: add tests for the PE image checks Ana Bobillo
2026-10-30  6:14 ` [PATCH 10/10] test: py: test invalid certificate lengths in signed images Ana Bobillo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be672b54-42c4-48fa-a7ad-994a7ab47ea7@gmail.com \
    --to=anabobillo3@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox