nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone
Blob Blame History Raw
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 Aug 2022 14:07:50 -0400
Subject: [PATCH] efi: allocate the initrd within the bounds expressed by the
 kernel

Currently on x86, only linux kernels built with CONFIG_RELOCATABLE for
x86_64 can be loaded above 4G, but the maximum address for the initramfs
is specified via a HdrS field.  This allows us to utilize that value,
and unless loading the kernel above 4G, uses the value present there.
If loading kernel above 4G is allowed, we assume loading the initramfs
above 4G also works; in practice this has been true in the kernel code
for quite some time.

Resolves: rhbz#2112134

Signed-off-by: Peter Jones <pjones@redhat.com>
(cherry picked from commit 3e08c35f316990913718a4457665e8f653ecaa52)
---
 grub-core/loader/i386/efi/linux.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
index b9cd443a9a..801e663fee 100644
--- a/grub-core/loader/i386/efi/linux.c
+++ b/grub-core/loader/i386/efi/linux.c
@@ -191,6 +191,8 @@ grub_linuxefi_unload (void *data)
   cmd_initrdefi->data = 0;
   grub_free (context);
 
+  max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
+
   return GRUB_ERR_NONE;
 }
 
@@ -439,11 +441,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
     }
 #endif
 
+  max_addresses[INITRD_MAX_ADDRESS].addr = lh->initrd_addr_max;
 #if defined(__x86_64__)
   if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G)
     {
       grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n");
       max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
+      max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
     }
   else
     {
@@ -573,6 +577,8 @@ fail:
 
   grub_dl_unref (my_mod);
 
+  max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
+
   if (lh)
     kernel_free (cmdline, lh->cmdline_size + 1);