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

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