]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
loader/efi/linux: Use shim loader image handle where available
authorMate Kukri <mate.kukri@canonical.com>
Tue, 8 Jul 2025 20:21:17 +0000 (21:21 +0100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Fri, 11 Jul 2025 21:11:35 +0000 (23:11 +0200)
Not reusing these handles will result in image measurements showing up
twice in the event log.

On the occasion add missing grub_free() call.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/loader/efi/linux.c

index 0ef4559aaae88872c25650e812f58041fd05f4e0..2c7c874f22915f5de02e846027e86032776689ec 100644 (file)
@@ -207,11 +207,20 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
   mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
   mempath[1].header.length = sizeof (grub_efi_device_path_t);
 
-  status = grub_efi_load_image (0, grub_efi_image_handle,
-                               (grub_efi_device_path_t *)mempath,
-                               (void *)addr, size, &image_handle);
-  if (status != GRUB_EFI_SUCCESS)
-    return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
+  image_handle = grub_efi_get_last_verified_image_handle ();
+  if (image_handle == NULL)
+    {
+      status = grub_efi_load_image (0, grub_efi_image_handle,
+                                   (grub_efi_device_path_t *) mempath,
+                                   (void *) addr, size, &image_handle);
+      if (status != GRUB_EFI_SUCCESS)
+       {
+         grub_free (mempath);
+         return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
+       }
+    }
+
+  grub_free (mempath);
 
   grub_dprintf ("linux", "linux command line: '%s'\n", args);