Re: [PATCH] loader/efi/fdt: Ensure FDT blob is 8-byte aligned
"Vladimir 'phcoder' Serbinenko" <[email protected]> Thu, 26 Feb 2026 17:53:08 +0300
| Newsgroups | org.gnu.grub-devel |
|---|---|
| Message-ID | <CAEaD8JPQc3YqJghpksuMjpM47X0Tp==AXGTrm6LgEzQw1xdH=w@mail.gmail.com> |
--===============1922973451122265194== Content-Type: multipart/alternative; boundary="000000000000ed2bd8064bbb471a" --000000000000ed2bd8064bbb471a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Regards Vladimir 'phcoder' Serbinenko Le mer. 25 f=C3=A9vr. 2026, 16:48, <[email protected]> a =C3=A9crit : > From: Mikhail Lappo <[email protected]> > > libfdt requires the FDT blob to be 8-byte aligned. The alignment is > validated in fdt_check_header(), and misaligned blobs may be rejected > or cause failures on architectures that enforce strict alignment. > > Currently the blob is allocated with grub_malloc(), which does not > guarantee 8-byte alignment. Actually it does. But I agree that explicit alignment is better. Or did you experience malloc returning anything less than 16-byte aligned? Reviewed-By: Vladimir Serbinenko<[email protected]> > Replace it with grub_memalign(8, size) > to ensure the required alignment. > > Signed-off-by: Mikhail Lappo <[email protected]> > --- > grub-core/loader/efi/fdt.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c > index e510b3491..f25d362d3 100644 > --- a/grub-core/loader/efi/fdt.c > +++ b/grub-core/loader/efi/fdt.c > @@ -38,6 +38,7 @@ static void *fdt; > #define FDT_ADDR_SIZE_EXTRA ((2 * grub_fdt_prop_entry_size > (sizeof(grub_uint32_t))) + \ > sizeof (FDT_ADDR_CELLS_STRING) + \ > sizeof (FDT_SIZE_CELLS_STRING)) > +#define FDT_BLOB_ALIGNMENT 8 > > static const struct grub_arg_option options_fdtdump[] =3D { > {"prop", 'p', 0, N_("Get property."), N_("prop"), ARG_TYPE_STRING}= , > @@ -145,7 +146,7 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ > ((unused)), > goto out; > > size =3D grub_file_size (dtb); > - blob =3D grub_malloc (size); > + blob =3D grub_memalign (FDT_BLOB_ALIGNMENT, size); > if (!blob) > goto out; > > -- > 2.44.0 > > > _______________________________________________ > Grub-devel mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/grub-devel > --000000000000ed2bd8064bbb471a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div><div><br></div><div><br></div><div data-smartmail=3D= "gmail_signature">Regards<br>Vladimir 'phcoder' Serbinenko<br></div= ><br><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" clas= s=3D"gmail_attr">Le mer. 25 f=C3=A9vr. 2026, 16:48, <<a href=3D"mailto:= [email protected]">[email protected]</a>> a =C3=A9crit=C2=A0:<br><= /div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le= ft:1px #ccc solid;padding-left:1ex">From: Mikhail Lappo <<a href=3D"mail= to:[email protected]" target=3D"_blank" rel=3D"noreferrer">miklelappo@gm= ail.com</a>><br> <br> libfdt requires the FDT blob to be 8-byte aligned. The alignment is<br> validated in fdt_check_header(), and misaligned blobs may be rejected<br> or cause failures on architectures that enforce strict alignment.<br> <br> Currently the blob is allocated with grub_malloc(), which does not<br> guarantee 8-byte alignment. </blockquote></div></div><div dir=3D"auto">Actu= ally it does. But I agree that explicit alignment is better. Or did you exp= erience malloc returning anything less than 16-byte aligned?</div><div dir= =3D"auto">Reviewed-By: Vladimir Serbinenko<<a href=3D"mailto:phcoder@gma= il.com">[email protected]</a>></div><div dir=3D"auto"><div class=3D"gmai= l_quote gmail_quote_container"><blockquote class=3D"gmail_quote" style=3D"m= argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Replace it wi= th grub_memalign(8, size)<br> to ensure the required alignment.<br> <br> Signed-off-by: Mikhail Lappo <<a href=3D"mailto:[email protected]" ta= rget=3D"_blank" rel=3D"noreferrer">[email protected]</a>><br> ---<br> =C2=A0grub-core/loader/efi/fdt.c | 3 ++-<br> =C2=A01 file changed, 2 insertions(+), 1 deletion(-)<br> <br> diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c<br> index e510b3491..f25d362d3 100644<br> --- a/grub-core/loader/efi/fdt.c<br> +++ b/grub-core/loader/efi/fdt.c<br> @@ -38,6 +38,7 @@ static void *fdt;<br> =C2=A0#define FDT_ADDR_SIZE_EXTRA ((2 * grub_fdt_prop_entry_size (sizeof(gr= ub_uint32_t))) + \<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeof (FDT_ADDR_CELLS_STRING) + \<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeof (FDT_SIZE_CELLS_STRING))<br> +#define FDT_BLOB_ALIGNMENT 8<br> <br> =C2=A0static const struct grub_arg_option options_fdtdump[] =3D {<br> =C2=A0 =C2=A0{"prop",=C2=A0 =C2=A0 =C2=A0'p', 0, N_("= ;Get property."), N_("prop"), ARG_TYPE_STRING},<br> @@ -145,7 +146,7 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ (= (unused)),<br> =C2=A0 =C2=A0 =C2=A0goto out;<br> <br> =C2=A0 =C2=A0size =3D grub_file_size (dtb);<br> -=C2=A0 blob =3D grub_malloc (size);<br> +=C2=A0 blob =3D grub_memalign (FDT_BLOB_ALIGNMENT, size);<br> =C2=A0 =C2=A0if (!blob)<br> =C2=A0 =C2=A0 =C2=A0goto out;<br> <br> -- <br> 2.44.0<br> <br> <br> _______________________________________________<br> Grub-devel mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noreferrer">= [email protected]</a><br> <a href=3D"https://lists.gnu.org/mailman/listinfo/grub-devel" rel=3D"norefe= rrer noreferrer" target=3D"_blank">https://lists.gnu.org/mailman/listinfo/g= rub-devel</a><br> </blockquote></div></div></div> --000000000000ed2bd8064bbb471a-- --===============1922973451122265194== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============1922973451122265194==--