grub-2.06 fails to load 64bit Multiboot2 ELF with regions above 4GiB

"Baksik, Fred [USA]" <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.bugs
Message-ID <1d91e73944c94ae6b8f307127ee3b826@BN2P110MB1190.NAMP110.PROD.OUTLOOK.COM>
GRUB2 fails to load a Multiboot2 ELF with loadable regions above 4GiB.  The error seen is "segment crosses 4 GiB border".

The 4 GiB border check was added as part of "multiboot2: Add support for relocatable images" commit a620876e3b32e4ea0c9a7b3541fcb9a4dd4fb9eb.
I believe this check should only apply when the multiboot2 image supports relocation via the MULTIBOOT_HEADER_TAG_RELOCATABLE tag.

Subject: [PATCH] multiboot2: check 4GiB limit for relocatable images only

---
grub-core/loader/multiboot_elfxx.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
index f2318e0..0ac11f0 100644
--- a/grub-core/loader/multiboot_elfxx.c
+++ b/grub-core/loader/multiboot_elfxx.c
@@ -92,10 +92,6 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
    highest_load = grub_max (highest_load, phdr(i)->p_paddr + phdr(i)->p_memsz);
       }
-#ifdef MULTIBOOT_LOAD_ELF64
-  if (highest_load >= 0x100000000)
-    return grub_error (GRUB_ERR_BAD_OS, "segment crosses 4 GiB border");
-#endif
   if (mld->relocatable)
     {
@@ -106,6 +102,11 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
              (long) mld->align, mld->preference, load_size,
              mld->avoid_efi_boot_services);
+#ifdef MULTIBOOT_LOAD_ELF64
+      if (highest_load >= 0x100000000)
+        return grub_error (GRUB_ERR_BAD_OS, "segment crosses 4 GiB border");
+#endif
+
       if (load_size > mld->max_addr || mld->min_addr > mld->max_addr - load_size)
    return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size");
--
2.31.1

Fred Baksik
Sr Prin Software Engineer
Systems | Mission
Mercury Systems
6675 Shiloh Road East, Alpharetta, GA 30005
+1 978.967.3405<tel:+1%20978.967.3405> office

[email protected]<mailto:[email protected]> | mrcy.com<https://www.mrcy.com/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.