All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
To: The development of GNU GRUB <grub-devel@gnu.org>,
	Javier Martinez Canillas <fmartine@redhat.com>
Cc: Daniel Kiper <daniel.kiper@oracle.com>, Peter Jones <pjones@redhat.com>
Subject: Re: GRUB error: unknown filesystem on ia64
Date: Fri, 16 Apr 2021 18:43:17 +0200	[thread overview]
Message-ID: <d34f511e-1108-8047-c73c-cb231c158b04@physik.fu-berlin.de> (raw)
In-Reply-To: <8affe4f2-5e8d-1bd5-35e2-6ef108086009@redhat.com>

Hi Javier!

On 4/16/21 5:21 PM, Javier Martinez Canillas wrote:
> Thanks for the binaries, as you said the ".data" and "mods" sections had
> wrong size and content. Could you please try the following patch [0] ?
> 
> It's an RFC since I'm not really an expert on binary formats, but there
> were a few problems with the patch you mentioned as far as I can tell.
> 
> I Cc'ed Daniel and Peter so they can correct me if I got anything wrong.
> 
> Best regards,
> Javier
> 
> [0]
> From 31c9864ff6543b624d404d8fabc9c517756a470a Mon Sep 17 00:00:00 2001
> From: Javier Martinez Canillas <javierm@redhat.com>
> Date: Fri, 16 Apr 2021 17:01:44 +0200
> Subject: [RFC PATCH] util/mkimage: Some fixes to PE binaries section size
>  calculation
> 
> Commit f60ba9e5945 (util/mkimage: Refactor section setup to use a helper)
> added a helper function to setup PE sections, but it caused regressions
> in some arches where the natural alignment lead to wrong section sizes.
> 
> This patch fixes a few things that were caused the section sizes to be
> calculated wrongly. These fixes are:
> 
>  * Only align the virtual memory addresses but not the raw data offsets.
>  * Use aligned sizes for virtual memory sizes but not for raw data sizes.
>  * Always align the sizes to set the virtual memory sizes.
> 
> These seems to not cause problems for x64 and aa64 EFI platforms but was
> a problem for ia64. Because the size of the ".data" and "mods" sections
> were wrong and didn't have the correct content. Which lead to GRUB not
> being able to load any built-in module.
> 
> Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
>  util/mkimage.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/util/mkimage.c b/util/mkimage.c
> index 8b475a69109..0d33f0e9766 100644
> --- a/util/mkimage.c
> +++ b/util/mkimage.c
> @@ -841,7 +841,7 @@ init_pe_section(const struct grub_install_image_target_desc *image_target,
>  
>    section->raw_data_offset = grub_host_to_target32 (*rda);
>    section->raw_data_size = grub_host_to_target32 (rsz);
> -  (*rda) = ALIGN_UP (*rda + rsz, GRUB_PE32_FILE_ALIGNMENT);
> +  (*rda) = *rda + rsz;
>  
>    section->characteristics = grub_host_to_target32 (characteristics);
>  
> @@ -1389,26 +1389,26 @@ grub_install_generate_image (const char *dir, const char *prefix,
>  
>  	section = init_pe_section (image_target, section, ".data",
>  				   &vma, scn_size, image_target->section_align,
> -				   &raw_data, scn_size,
> +				   &raw_data, layout.kernel_size - layout.exec_size,
>  				   GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
>  				   GRUB_PE32_SCN_MEM_READ |
>  				   GRUB_PE32_SCN_MEM_WRITE);
>  
> -	scn_size = pe_size - layout.reloc_size - raw_data;
> +	scn_size = ALIGN_UP (pe_size - layout.reloc_size - raw_data, GRUB_PE32_FILE_ALIGNMENT);
>  	section = init_pe_section (image_target, section, "mods",
>  				   &vma, scn_size, image_target->section_align,
> -				   &raw_data, scn_size,
> +				   &raw_data, pe_size - layout.reloc_size - raw_data,
>  				   GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
>  				   GRUB_PE32_SCN_MEM_READ |
>  				   GRUB_PE32_SCN_MEM_WRITE);
>  
> -	scn_size = layout.reloc_size;
> +	scn_size = ALIGN_UP (layout.reloc_size, GRUB_PE32_FILE_ALIGNMENT);
>  	PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (vma);
>  	PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (scn_size);
>  	memcpy (pe_img + raw_data, layout.reloc_section, scn_size);
>  	init_pe_section (image_target, section, ".reloc",
>  			 &vma, scn_size, image_target->section_align,
> -			 &raw_data, scn_size,
> +			 &raw_data, layout.reloc_size,
>  			 GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
>  			 GRUB_PE32_SCN_MEM_DISCARDABLE |
>  			 GRUB_PE32_SCN_MEM_READ);
> 

It seems the patch no longer applies due to the changes introduced by the --sbat
option [1].

Could you rebase your patch? Meanwhile I'm testing it with a manual rebase applied.

Adrian

> [1] http://git.savannah.gnu.org/cgit/grub.git/commit/util?id=b11547137703bbc642114a816233a5b6fed61b06

-- 
 .''`.  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	other threads:[~2021-04-16 16:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 18:22 GRUB error: unknown filesystem on ia64 John Paul Adrian Glaubitz
2021-03-26 18:01 ` Daniel Kiper
2021-03-26 18:28   ` John Paul Adrian Glaubitz
2021-03-26 18:43     ` Daniel Kiper
2021-04-08 16:45       ` John Paul Adrian Glaubitz
2021-04-08 17:10         ` Javier Martinez Canillas
2021-04-08 17:30           ` John Paul Adrian Glaubitz
2021-04-10  9:40             ` John Paul Adrian Glaubitz
2021-04-12  6:21               ` Javier Martinez Canillas
2021-04-12  6:57                 ` John Paul Adrian Glaubitz
2021-04-16 15:21                   ` Javier Martinez Canillas
2021-04-16 16:43                     ` John Paul Adrian Glaubitz [this message]
2021-04-16 16:55                       ` John Paul Adrian Glaubitz
2021-04-16 20:14                         ` Javier Martinez Canillas
2021-04-16 20:32                           ` John Paul Adrian Glaubitz
2021-04-16 21:32                             ` Javier Martinez Canillas
2021-04-19 15:33                               ` John Paul Adrian Glaubitz
2021-04-19 17:56                                 ` Javier Martinez Canillas
2021-04-21 17:54                                   ` Javier Martinez Canillas
2021-04-16 15:21                   ` Javier Martinez Canillas
2021-06-16 14:22 Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d34f511e-1108-8047-c73c-cb231c158b04@physik.fu-berlin.de \
    --to=glaubitz@physik.fu-berlin.de \
    --cc=daniel.kiper@oracle.com \
    --cc=fmartine@redhat.com \
    --cc=grub-devel@gnu.org \
    --cc=pjones@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.