nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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