From: Mate Kukri Date: Tue, 8 Jul 2025 20:21:16 +0000 (+0100) Subject: loader/efi/chainloader: Use shim loader image handle where available X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1b9a84e63b18692111fc2a0b464796aedbb2dd72;p=thirdparty%2Fgrub.git loader/efi/chainloader: Use shim loader image handle where available Not reusing these handles will result in image measurements showing up twice in the event log. Signed-off-by: Mate Kukri Reviewed-by: Daniel Kiper --- diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 11b64ac1b..e77bd863c 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -337,16 +338,20 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } #endif - status = grub_efi_load_image (0, grub_efi_image_handle, file_path, - boot_image, size, &image_handle); - if (status != GRUB_EFI_SUCCESS) + image_handle = grub_efi_get_last_verified_image_handle (); + if (image_handle == NULL) { - if (status == GRUB_EFI_OUT_OF_RESOURCES) - grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources"); - else - grub_error (GRUB_ERR_BAD_OS, "cannot load image"); + status = grub_efi_load_image (0, grub_efi_image_handle, file_path, + boot_image, size, &image_handle); + if (status != GRUB_EFI_SUCCESS) + { + if (status == GRUB_EFI_OUT_OF_RESOURCES) + grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources"); + else + grub_error (GRUB_ERR_BAD_OS, "cannot load image"); - goto fail; + goto fail; + } } /* LoadImage does not set a device handler when the image is