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 <[email protected]> Signed-off-by: Javier Martinez Canillas <[email protected]> --- Hello, this is an RFC because I want someone else more familiar with this to double check that this approach is sane. It would be also useful if someone can test on an aarch64 machine, I have compared the generated EFI binaries and are the same in both cases. But still it seems to me that an explicit alignment is needed for EM_AARCH64. Best regards, Javier util/grub-mkimagexx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 00f49ccaaaf..2d0c9a0cb6b 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -2375,6 +2375,10 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, layout->got_off = layout->kernel_size; layout->kernel_size += ALIGN_UP (layout->got_size, 16); + + if (image_target->id == IMAGE_EFI) + layout->kernel_size = ALIGN_UP (layout->kernel_size, + image_target->section_align); } if (image_target->elf_target == EM_AARCH64) { @@ -2386,6 +2390,11 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, layout->got_off = layout->kernel_size; layout->kernel_size += ALIGN_UP (layout->got_size, 16); + + + if (image_target->id == IMAGE_EFI) + layout->kernel_size = ALIGN_UP (layout->kernel_size, + image_target->section_align); } #endif } -- 2.31.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
