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>
Subject: [PATCH v3 08/11] efi_loader: refuse a PE image of an unknown subsystem
Date: Fri, 06 Nov 2026 21:57:08 +0000	[thread overview]
Message-ID: <dd3c51cb-a55c-4e3e-9408-7899706de312@gmail.com> (raw)
In-Reply-To: <dacef858-56d7-4708-b784-16b0133bb6aa@gmail.com>

From: Ana Bobillo <anabobillo3@gmail.com>

efi_load_pe() loads an image whose Subsystem field is none of the UEFI
image types as an application: efi_set_code_and_data_type() only logs
"invalid image type". Such an image is then not measured by
tcg2_measure_pe_image(), and efi_start_image() does not measure its
invocation either, so with measured boot it runs without a trace in
PCR 4.

The UEFI specification defines subsystems 10, 11 and 12 for UEFI images,
and LoadImage() returns EFI_UNSUPPORTED for an image type that is not
supported. EDK2 does so in CoreLoadPeImage(). Do the same here, also
for IMAGE_SUBSYSTEM_EFI_ROM, which was given a runtime driver's memory
types but could not be measured either.

Fixes: 36b41a3cedd6 ("efi_loader: allocate correct memory type for EFI image")
Suggested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 lib/efi_loader/efi_image_loader.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
index 8f48d8fb5a5..67b83af0e8e 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -252,8 +252,10 @@ static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
  * @loaded_image_info:	image descriptor
  * @image_type:		field Subsystem of the optional header for
  *			Windows specific field
+ * Return:		status code, EFI_UNSUPPORTED if @image_type is not
+ *			one of the UEFI image types
  */
-static void efi_set_code_and_data_type(
+static efi_status_t efi_set_code_and_data_type(
 			struct efi_loaded_image *loaded_image_info,
 			uint16_t image_type)
 {
@@ -267,17 +269,15 @@ static void efi_set_code_and_data_type(
 		loaded_image_info->image_data_type = EFI_BOOT_SERVICES_DATA;
 		break;
 	case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
-	case IMAGE_SUBSYSTEM_EFI_ROM:
 		loaded_image_info->image_code_type = EFI_RUNTIME_SERVICES_CODE;
 		loaded_image_info->image_data_type = EFI_RUNTIME_SERVICES_DATA;
 		break;
 	default:
 		log_err("invalid image type: %u\n", image_type);
-		/* Let's assume it is an application */
-		loaded_image_info->image_code_type = EFI_LOADER_CODE;
-		loaded_image_info->image_data_type = EFI_LOADER_DATA;
-		break;
+		return EFI_UNSUPPORTED;
 	}
+
+	return EFI_SUCCESS;
 }
 
 /**
@@ -1104,7 +1104,10 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
 		IMAGE_NT_HEADERS64 *nt64 = (void *)nt;
 		IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader;
 		image_base = opt->ImageBase;
-		efi_set_code_and_data_type(loaded_image_info, opt->Subsystem);
+		ret = efi_set_code_and_data_type(loaded_image_info,
+						 opt->Subsystem);
+		if (ret != EFI_SUCCESS)
+			goto err;
 		handle->image_type = opt->Subsystem;
 		efi_reloc = efi_alloc_aligned_pages(virt_size,
 						    loaded_image_info->image_code_type,
@@ -1121,7 +1124,10 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
 	} else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
 		IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader;
 		image_base = opt->ImageBase;
-		efi_set_code_and_data_type(loaded_image_info, opt->Subsystem);
+		ret = efi_set_code_and_data_type(loaded_image_info,
+						 opt->Subsystem);
+		if (ret != EFI_SUCCESS)
+			goto err;
 		handle->image_type = opt->Subsystem;
 		efi_reloc = efi_alloc_aligned_pages(virt_size,
 						    loaded_image_info->image_code_type,

  parent reply	other threads:[~2026-11-06 21:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 21:56 [PATCH v3 00/11] efi_loader: check PE images before using them Ana Bobillo
2026-11-06 21:56 ` [PATCH v3 01/11] efi_loader: check the NT header size in efi_check_pe() Ana Bobillo
2026-11-06 21:56 ` [PATCH v3 02/11] efi_loader: check the PE image ranges in efi_image_parse() Ana Bobillo
2026-11-06 21:56 ` [PATCH v3 03/11] efi_loader: reject a PE section whose end wraps around Ana Bobillo
2026-11-06 21:56 ` [PATCH v3 04/11] efi_loader: check PE section raw data against the image size Ana Bobillo
2026-11-06 21:56 ` [PATCH v3 05/11] efi_loader: make room for the PE headers in the loaded image Ana Bobillo
2026-11-06 21:56 ` [PATCH v3 06/11] efi_loader: check the relocation table against the image size Ana Bobillo
2026-11-06 21:57 ` [PATCH v3 07/11] efi_loader: check certificate lengths in efi_image_authenticate() Ana Bobillo
2026-11-06 21:57 ` Ana Bobillo [this message]
2026-11-06 21:57 ` [PATCH v3 09/11] efi_loader: do not start an image that cannot be measured Ana Bobillo
2026-11-06 21:57 ` [PATCH v3 10/11] test: lib: add tests for the PE image checks Ana Bobillo
2026-11-06 21:57 ` [PATCH v3 11/11] 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=dd3c51cb-a55c-4e3e-9408-7899706de312@gmail.com \
    --to=anabobillo3@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --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