grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH v2] util/mkimage: Fix wrong PE32+ section sizes for some arch


From: Javier Martinez Canillas
Subject: [RFC PATCH v2] util/mkimage: Fix wrong PE32+ section sizes for some arches
Date: Mon, 26 Apr 2021 09:21:02 +0200

Commit f60ba9e5945 (util/mkimage: Refactor section setup to use a helper)
added a helper function to setup PE sections. But it also changed how the
raw data offsets were calculated since all the section sizes are aligned.

But for some platforms (i.e: ia64 and aa64) the kernel image size wasn't
aligned using the section alignment, which causes the PE section headers
to not match the actual section sizes in the PE32+ binary file.

This caused problems on ia64 EFI machines, since the .data section size
is bigger than the actual section in the PE32+ binary, overlapping with
part of the mods section. That leads to GRUB not being able to load any
built-in module.

Fix it by aligning the kernel_size to the section alignment, that makes
the sizes and offsets in the PE section headers to match the sections
in the PE32+ binary file.

Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---

Changes in v2:
- Align up for any arch in the is_relocatable (image_target) patch and
  not only for MKIMAGE_ELF64 or EM_AARCH64 (suggested by Daniel Kiper).

 util/grub-mkimagexx.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index 00f49ccaaaf..73646f12f14 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -2388,6 +2388,11 @@ SUFFIX (grub_mkimage_load_image) (const char 
*kernel_path,
          layout->kernel_size += ALIGN_UP (layout->got_size, 16);
        }
 #endif
+
+      if (image_target->id == IMAGE_EFI)
+        layout->kernel_size = ALIGN_UP (layout->kernel_size + 
image_target->vaddr_offset,
+                                        image_target->section_align)
+          - image_target->vaddr_offset;
     }
   else
     {
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]