[PATCH 0/2] bootconfig: Fix max size padding and initrd memory leak

From: Masami Hiramatsu (Google)

Date: Tue Nov 17 2026 - 18:47:31 EST


Hi,

Here are 2 patches to fix pre-existing bootconfig issues around the
bootconfig attached to the initrd image.

[1/2] fixes the bootconfig loader in both the kernel and the bootconfig
tool to exclude the 4-byte alignment padding from the maximum bootconfig
size check. When attaching a bootconfig to an initrd image, the tool
appends 0-3 null padding bytes and includes them in the footer size
field. Although the documentation states that the maximum size (32767
bytes including the terminal null) does not include these padding null
bytes, both the kernel and the tool checked the raw footer size directly
against XBC_DATA_MAX, rejecting a maximum-size bootconfig depending on
the initrd size. This allows up to 3 trailing null padding bytes in the
footer size and strips them before checking XBC_DATA_MAX and parsing.

[2/2] fixes a memory leak of the initrd pages used by the bootconfig.
get_boot_config_from_initrd() trims the bootconfig by decrementing
initrd_end, but the initrd memory is freed with the trimmed initrd_end
while the whole initrd including the bootconfig has been reserved.
Thus the full pages used only by the bootconfig are never freed (up to
8 pages for a 32KB bootconfig). This saves the original initrd_end and
restores it before freeing the initrd memory. If the initrd is retained,
the trimmed initrd_end is kept so that /sys/firmware/initrd does not
expose the bootconfig.

Thank you,

---
base-commit: 381b391bfaa3f10d52da4740529804b0b6b8160d

Masami Hiramatsu (Google) (2):
bootconfig: Exclude alignment padding from bootconfig max size
bootconfig: Free the initrd memory used by bootconfig


include/linux/bootconfig.h | 24 ++++++++++++++++++++++++
include/linux/initrd.h | 2 ++
init/initramfs.c | 10 ++++++++++
init/main.c | 31 ++++++++++++++++++++++---------
tools/bootconfig/main.c | 14 ++++++++++----
tools/bootconfig/test-bootconfig.sh | 17 +++++++++++++++--
6 files changed, 83 insertions(+), 15 deletions(-)

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>