On Tue, 3 Nov 2026 at 18:13, Ana Bobillo <[email protected]> wrote: > > From: Ana Bobillo <[email protected]> > > 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 <[email protected]> > Signed-off-by: Ana Bobillo <[email protected]> > ---
Reviewed-by: Ilias Apalodimas <[email protected]> > 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 5a784bfb43a..a0879f18621 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; > } > > /** > @@ -1109,7 +1109,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, > @@ -1126,7 +1129,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,
