Regards
Vladimir 'phcoder' Serbinenko

Le mer. 25 févr. 2026, 16:48, <[email protected]> a écrit :

> 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[] = {
>    {"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 = grub_file_size (dtb);
> -  blob = grub_malloc (size);
> +  blob = 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
>
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to