Blame SOURCES/0273-EFI-allocate-kernel-in-EFI_RUNTIME_SERVICES_CODE-ins.patch

1c6ba0
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
1c6ba0
From: Peter Jones <pjones@redhat.com>
1c6ba0
Date: Wed, 9 Feb 2022 16:08:20 -0500
1c6ba0
Subject: [PATCH] EFI: allocate kernel in EFI_RUNTIME_SERVICES_CODE instead of
1c6ba0
 EFI_LOADER_DATA.
1c6ba0
1c6ba0
On some of the firmwares with more security mitigations, EFI_LOADER_DATA
1c6ba0
doesn't get you executable memory, and we take a fault and reboot when
1c6ba0
we enter kernel.
1c6ba0
1c6ba0
This patch correctly allocates the kernel code as EFI_RUNTIME_SERVICES_CODE
1c6ba0
rather than EFI_LOADER_DATA.
1c6ba0
1c6ba0
Signed-off-by: Peter Jones <pjones@redhat.com>
1c6ba0
[rharwood: use kernel_size]
1c6ba0
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
1c6ba0
(cherry picked from commit 8b31058a12d3e85f0f0180ac90b98d6465fccbb7)
1c6ba0
---
1c6ba0
 grub-core/loader/i386/efi/linux.c | 19 +++++++++++++------
1c6ba0
 1 file changed, 13 insertions(+), 6 deletions(-)
1c6ba0
1c6ba0
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
1c6ba0
index d24553a79d..b832c85728 100644
1c6ba0
--- a/grub-core/loader/i386/efi/linux.c
1c6ba0
+++ b/grub-core/loader/i386/efi/linux.c
1c6ba0
@@ -87,7 +87,9 @@ kernel_free(void *addr, grub_efi_uintn_t size)
1c6ba0
 }
1c6ba0
 
1c6ba0
 static void *
1c6ba0
-kernel_alloc(grub_efi_uintn_t size, const char * const errmsg)
1c6ba0
+kernel_alloc(grub_efi_uintn_t size,
1c6ba0
+	     grub_efi_memory_type_t memtype,
1c6ba0
+	     const char * const errmsg)
1c6ba0
 {
1c6ba0
   void *addr = 0;
1c6ba0
   unsigned int i;
1c6ba0
@@ -113,7 +115,7 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg)
1c6ba0
       prev_max = max;
1c6ba0
       addr = grub_efi_allocate_pages_real (max, pages,
1c6ba0
 					   max_addresses[i].alloc_type,
1c6ba0
-					   GRUB_EFI_LOADER_DATA);
1c6ba0
+					   memtype);
1c6ba0
       if (addr)
1c6ba0
 	grub_dprintf ("linux", "Allocated at %p\n", addr);
1c6ba0
     }
1c6ba0
@@ -243,7 +245,8 @@ grub_cmd_initrd (grub_command_t cmd, int argc, char *argv[])
1c6ba0
 	}
1c6ba0
     }
1c6ba0
 
1c6ba0
-  initrd_mem = kernel_alloc(size, N_("can't allocate initrd"));
1c6ba0
+  initrd_mem = kernel_alloc(size, GRUB_EFI_RUNTIME_SERVICES_DATA,
1c6ba0
+			    N_("can't allocate initrd"));
1c6ba0
   if (initrd_mem == NULL)
1c6ba0
     goto fail;
1c6ba0
   grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem);
1c6ba0
@@ -406,7 +409,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
1c6ba0
     }
1c6ba0
 #endif
1c6ba0
 
1c6ba0
-  params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters");
1c6ba0
+  params = kernel_alloc (sizeof(*params), GRUB_EFI_RUNTIME_SERVICES_DATA,
1c6ba0
+			 "cannot allocate kernel parameters");
1c6ba0
   if (!params)
1c6ba0
     goto fail;
1c6ba0
   grub_dprintf ("linux", "params = %p\n", params);
1c6ba0
@@ -428,7 +432,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
1c6ba0
   grub_dprintf ("linux", "new lh is at %p\n", lh);
1c6ba0
 
1c6ba0
   grub_dprintf ("linux", "setting up cmdline\n");
1c6ba0
-  cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline"));
1c6ba0
+  cmdline = kernel_alloc (lh->cmdline_size + 1,
1c6ba0
+			  GRUB_EFI_RUNTIME_SERVICES_DATA,
1c6ba0
+			  N_("can't allocate cmdline"));
1c6ba0
   if (!cmdline)
1c6ba0
     goto fail;
1c6ba0
   grub_dprintf ("linux", "cmdline = %p\n", cmdline);
1c6ba0
@@ -474,7 +480,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
1c6ba0
   max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
1c6ba0
   max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
1c6ba0
   kernel_size = lh->init_size;
1c6ba0
-  kernel_mem = kernel_alloc (kernel_size, N_("can't allocate kernel"));
1c6ba0
+  kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE,
1c6ba0
+			     N_("can't allocate kernel"));
1c6ba0
   restore_addresses();
1c6ba0
   if (!kernel_mem)
1c6ba0
     goto fail;