nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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