Re: [PATCH] bootconfig: Fix unaligned access when building footer

From: Ben Hutchings
Date: Wed Jul 23 2025 - 16:34:27 EST


On Thu, 2025-07-24 at 00:37 +0900, Masami Hiramatsu wrote:
> On Wed, 23 Jul 2025 12:49:25 +0200
> Ben Hutchings <benh@xxxxxxxxxx> wrote:
[...]
> > static int apply_xbc(const char *path, const char *xbc_path)
> > {
> > - char *buf, *data, *p;
> > + struct {
> > + uint32_t size;
> > + uint32_t csum;
> > + char magic[BOOTCONFIG_MAGIC_LEN];
> > + } footer;
>
> Don't we need __attribute__((__packed__)) for the footer?

I don't see any reason for there to be padding in this structure, since
it has an alignment of 4 and the size of each member is a multiple of 4.

I included an assertion that there is no padding:

[...]
> > + memcpy(footer.magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
> > + static_assert(sizeof(footer) == BOOTCONFIG_FOOTER_SIZE);
> > + memcpy(data + size, &footer, BOOTCONFIG_FOOTER_SIZE);
[...]

Ben.

--
Ben Hutchings - Debian developer, member of kernel, installer and LTS
teams

Attachment: signature.asc
Description: This is a digitally signed message part