I tried report this issue to the bug-grub mailing list but didn't see the Bug 
Tracker get updated.
I'd like to get this reported so anyone else using multiboot2 to boot and 
embedded RTOS knows of this problem.

I also supplied a patch that fixes the issue.

Regards,
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

fred.bak...@mrcy.com<mailto:fred.bak...@mrcy.com> | 
mrcy.com<https://www.mrcy.com/>

From: Baksik, Fred [USA]
Sent: Wednesday, May 24, 2023 9:14 AM
To: bug-g...@gnu.org
Subject: grub-2.06 fails to load 64bit Multiboot2 ELF with regions above 4GiB

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

fred.bak...@mrcy.com<mailto:fred.bak...@mrcy.com> | 
mrcy.com<https://www.mrcy.com/>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to