Re: [PATCH] loader/efi/fdt: Ensure FDT blob is 8-byte aligned
Mikle Lappo <[email protected]> Thu, 26 Feb 2026 09:14:55 +0100
| Newsgroups | org.gnu.grub-devel |
|---|---|
| Message-ID | <CAEnBdDqaBMen8voCOcEKBiUtEV1KsKHVCiLUQ_rG6cUbaEtqcg@mail.gmail.com> |
--===============6847191042415737431== Content-Type: multipart/alternative; boundary="00000000000064633d064bb5b920" --00000000000064633d064bb5b920 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Add maintainers into CC On Wed, Feb 25, 2026 at 2:07=E2=80=AFPM <[email protected]> wrote: > 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. 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 > > --00000000000064633d064bb5b920 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Add maintainers into CC</div><br><div class=3D"gmail_= quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, = Feb 25, 2026 at 2:07=E2=80=AFPM <<a href=3D"mailto:[email protected]"= >[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_qu= ote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-st= yle:solid;border-left-color:rgb(204,204,204);padding-left:1ex">From: Mikhai= l Lappo <<a href=3D"mailto:[email protected]" target=3D"_blank">mikle= [email protected]</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. Replace it with 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">[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> </blockquote></div></div> --00000000000064633d064bb5b920-- --===============6847191042415737431== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============6847191042415737431==--