File 0012-loader-efi-linux-Use-shim-loader-image-handle-where-.patch of Package grub2

From e4855838e156b3509a2fd774c69ab4681e774427 Mon Sep 17 00:00:00 2001
From: Mate Kukri <mate.kukri@canonical.com>
Date: Tue, 8 Jul 2025 21:21:17 +0100
Subject: [PATCH 12/13] loader/efi/linux: Use shim loader image handle where
 available

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 | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
index 993d18546..394df6039 100644
--- a/grub-core/loader/efi/linux.c
+++ b/grub-core/loader/efi/linux.c
@@ -206,11 +206,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);
 
-- 
2.50.1

openSUSE Build Service is sponsored by