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

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