nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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