nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0283-efi-allocate-the-initrd-within-the-bounds-expressed-.patch

d3c3ab
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d3c3ab
From: Peter Jones <pjones@redhat.com>
d3c3ab
Date: Mon, 1 Aug 2022 14:07:50 -0400
d3c3ab
Subject: [PATCH] efi: allocate the initrd within the bounds expressed by the
d3c3ab
 kernel
d3c3ab
d3c3ab
Currently on x86, only linux kernels built with CONFIG_RELOCATABLE for
d3c3ab
x86_64 can be loaded above 4G, but the maximum address for the initramfs
d3c3ab
is specified via a HdrS field.  This allows us to utilize that value,
d3c3ab
and unless loading the kernel above 4G, uses the value present there.
d3c3ab
If loading kernel above 4G is allowed, we assume loading the initramfs
d3c3ab
above 4G also works; in practice this has been true in the kernel code
d3c3ab
for quite some time.
d3c3ab
d3c3ab
Resolves: rhbz#2112134
d3c3ab
d3c3ab
Signed-off-by: Peter Jones <pjones@redhat.com>
d3c3ab
(cherry picked from commit 3e08c35f316990913718a4457665e8f653ecaa52)
d3c3ab
---
d3c3ab
 grub-core/loader/i386/efi/linux.c | 6 ++++++
d3c3ab
 1 file changed, 6 insertions(+)
d3c3ab
d3c3ab
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
d3c3ab
index b9cd443a9a..801e663fee 100644
d3c3ab
--- a/grub-core/loader/i386/efi/linux.c
d3c3ab
+++ b/grub-core/loader/i386/efi/linux.c
d3c3ab
@@ -191,6 +191,8 @@ grub_linuxefi_unload (void *data)
d3c3ab
   cmd_initrdefi->data = 0;
d3c3ab
   grub_free (context);
d3c3ab
 
d3c3ab
+  max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
d3c3ab
+
d3c3ab
   return GRUB_ERR_NONE;
d3c3ab
 }
d3c3ab
 
d3c3ab
@@ -439,11 +441,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
d3c3ab
     }
d3c3ab
 #endif
d3c3ab
 
d3c3ab
+  max_addresses[INITRD_MAX_ADDRESS].addr = lh->initrd_addr_max;
d3c3ab
 #if defined(__x86_64__)
d3c3ab
   if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G)
d3c3ab
     {
d3c3ab
       grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n");
d3c3ab
       max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
d3c3ab
+      max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
d3c3ab
     }
d3c3ab
   else
d3c3ab
     {
d3c3ab
@@ -573,6 +577,8 @@ fail:
d3c3ab
 
d3c3ab
   grub_dl_unref (my_mod);
d3c3ab
 
d3c3ab
+  max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
d3c3ab
+
d3c3ab
   if (lh)
d3c3ab
     kernel_free (cmdline, lh->cmdline_size + 1);
d3c3ab