grub-devel
[Top][All Lists]
Advanced

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

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


From: John Paul Adrian Glaubitz
Subject: Re: [RFC PATCH v2] util/mkimage: Fix wrong PE32+ section sizes for some arches
Date: Mon, 26 Apr 2021 09:52:23 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0

On 4/26/21 9:21 AM, Javier Martinez Canillas wrote:
> 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
>      {
> 

Verified to fix the issue on ia64.

Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz@debian.org
`. `'   Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913



reply via email to

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