Blame SOURCES/0506-loader-efi-chainloader-grub_load_and_start_image-doe.patch

b9d01e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b9d01e
From: Chris Coulson <chris.coulson@canonical.com>
b9d01e
Date: Thu, 28 Apr 2022 21:53:36 +0100
b9d01e
Subject: [PATCH] loader/efi/chainloader: grub_load_and_start_image doesn't
b9d01e
 load and start
b9d01e
b9d01e
grub_load_and_start_image only loads an image - it still requires the
b9d01e
caller to start it. This renames it to grub_load_image.
b9d01e
b9d01e
It's called from 2 places:
b9d01e
- grub_cmd_chainloader when not using the shim protocol.
b9d01e
- grub_secureboot_chainloader_boot if handle_image returns an error.
b9d01e
In this case, the image is loaded and then nothing else happens which
b9d01e
seems strange. I assume the intention is that it falls back to LoadImage
b9d01e
and StartImage if handle_image fails, so I've made it do that.
b9d01e
b9d01e
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
b9d01e
(cherry picked from commit b4d70820a65c00561045856b7b8355461a9545f6)
b9d01e
(cherry picked from commit 05b16a6be50b1910609740a66b561276fa490538)
b9d01e
(cherry picked from commit 16486a34f3aa41a94e334e86db1a1e21e9b0a45f)
b9d01e
---
b9d01e
 grub-core/loader/efi/chainloader.c | 16 +++++++++++++---
b9d01e
 1 file changed, 13 insertions(+), 3 deletions(-)
b9d01e
b9d01e
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
b9d01e
index 29663f7180..d75d345003 100644
b9d01e
--- a/grub-core/loader/efi/chainloader.c
b9d01e
+++ b/grub-core/loader/efi/chainloader.c
b9d01e
@@ -835,7 +835,7 @@ grub_secureboot_chainloader_unload (void)
b9d01e
 }
b9d01e
 
b9d01e
 static grub_err_t
b9d01e
-grub_load_and_start_image(void *boot_image)
b9d01e
+grub_load_image(void *boot_image)
b9d01e
 {
b9d01e
   grub_efi_boot_services_t *b;
b9d01e
   grub_efi_status_t status;
b9d01e
@@ -877,13 +877,23 @@ grub_load_and_start_image(void *boot_image)
b9d01e
 static grub_err_t
b9d01e
 grub_secureboot_chainloader_boot (void)
b9d01e
 {
b9d01e
+  grub_efi_boot_services_t *b;
b9d01e
   int rc;
b9d01e
+
b9d01e
   rc = handle_image ((void *)(unsigned long)address, fsize);
b9d01e
   if (rc == 0)
b9d01e
     {
b9d01e
-      grub_load_and_start_image((void *)(unsigned long)address);
b9d01e
+      /* We weren't able to attempt to execute the image, so fall back
b9d01e
+       * to LoadImage / StartImage.
b9d01e
+       */
b9d01e
+      rc = grub_load_image((void *)(unsigned long)address);
b9d01e
+      if (rc == 0)
b9d01e
+        grub_chainloader_boot ();
b9d01e
     }
b9d01e
 
b9d01e
+  b = grub_efi_system_table->boot_services;
b9d01e
+  efi_call_1 (b->unload_image, image_handle);
b9d01e
+
b9d01e
   grub_loader_unset ();
b9d01e
   return grub_errno;
b9d01e
 }
b9d01e
@@ -1072,7 +1082,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
b9d01e
     }
b9d01e
   else if (rc == 0)
b9d01e
     {
b9d01e
-      grub_load_and_start_image(boot_image);
b9d01e
+      grub_load_image(boot_image);
b9d01e
       grub_file_close (file);
b9d01e
       grub_device_close (dev);
b9d01e
       grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0);