Re: [PATCH 1/2] bootconfig: Exclude alignment padding from bootconfig max size
From: Breno Leitao
Date: Fri Nov 20 2026 - 13:48:44 EST
On Wed, Nov 18, 2026 at 08:47:30AM +0900, Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
>
> When attaching a bootconfig to an initrd image, apply_xbc() appends 0-3
> null padding bytes to align the total image size to 4 bytes and includes
> those padding bytes in the footer size field. As documented in
> Documentation/admin-guide/bootconfig.rst, the maximum bootconfig size
> (XBC_DATA_MAX, 32767 bytes including the terminal null) is not supposed
> to include these padding null characters.
>
> However, both load_xbc_from_initrd() in tools/bootconfig and
> get_boot_config_from_initrd() / xbc_init() in the kernel check the raw
> footer size directly against XBC_DATA_MAX. As a result, a valid
> 32766-byte config (size = 32767 with the terminal null) gets a footer
> size of 32768..32770 when alignment padding is added, and is rejected
> with "bootconfig size is too big" depending on the initrd size.
>
> Define XBC_DATA_MAX_PADDED (XBC_DATA_MAX + BOOTCONFIG_ALIGN - 1) for the
> raw trailer size check, and add xbc_exclude_padding() to strip up to
> BOOTCONFIG_ALIGN - 1 trailing null padding bytes (keeping the terminal
> null byte) before checking the unpadded bootconfig size against
> XBC_DATA_MAX and passing it to xbc_init(). Keep using the raw footer
> size when truncating or trimming the initrd so that both the bootconfig
> and its alignment padding are removed.
>
> Also expand test-bootconfig.sh to verify applying, reading back, and
> deleting a maximum-size bootconfig across all 4 alignment paddings.
>
> Fixes: e1cef2d4c379 ("tools/bootconfig: Align the bootconfig applied initrd image size to 4")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
Reviewed-by: Breno Leitao <leitao@xxxxxxxxxx>