nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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