include/linux/bootconfig.h | 4 + init/main.c | 2 - lib/bootconfig.c | 45 +++++++++++---- tools/bootconfig/main.c | 106 +++++++++++++++-------------------- tools/bootconfig/test-bootconfig.sh | 12 ++++ 5 files changed, 95 insertions(+), 74 deletions(-)
Hi,
Here are v2 patches for bootconfig to rejects unexpected config data after
null character and other cleanups including tools/bootconfig to consolidate
bootconfig initialization with errors, and skipping internal tree sanity
check in kernel.
The previous version is here:
https://lore.kernel.org/all/178896921555.177508.434402948295885560.stgit@devnote2/
This version removes redundant buffer copy in init_xbc_with_error() [2/4]
and moves BOOTCONFIG_FOOTER_SIZE to include/linux/bootconfig.h[4/4].
Thank you,
---
base-commit: 7812d6dab0698001e50e8c2f901e17da3eb6f429
Masami Hiramatsu (Google) (4):
bootconfig: Reject unexpected data after null character
tools/bootconfig: Consolidate xbc_init() to error message wrapper
bootconfig: Skip internal tree sanity checks in kernel
bootconfig: Move BOOTCONFIG_FOOTER_SIZE to include/linux/bootconfig.h
include/linux/bootconfig.h | 4 +
init/main.c | 2 -
lib/bootconfig.c | 45 +++++++++++----
tools/bootconfig/main.c | 106 +++++++++++++++--------------------
tools/bootconfig/test-bootconfig.sh | 12 ++++
5 files changed, 95 insertions(+), 74 deletions(-)
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
On Fri, 11 Sep 2026 23:12:56 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> Hi,
>
> Here are v2 patches for bootconfig to rejects unexpected config data after
> null character and other cleanups including tools/bootconfig to consolidate
> bootconfig initialization with errors, and skipping internal tree sanity
> check in kernel.
>
> ...
>
Thanks, I've updateed mm.git's mm-nonmm-unstable branch to this version,
> This version removes redundant buffer copy in init_xbc_with_error() [2/4]
> and moves BOOTCONFIG_FOOTER_SIZE to include/linux/bootconfig.h[4/4].
Here's how v2 altered mm.git:
include/linux/bootconfig.h | 4 ++++
init/main.c | 2 +-
tools/bootconfig/main.c | 14 +-------------
3 files changed, 6 insertions(+), 14 deletions(-)
--- a/include/linux/bootconfig.h~b
+++ a/include/linux/bootconfig.h
@@ -27,6 +27,10 @@ bool __init cmdline_has_extra_options(vo
#define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT)
#define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1)
+/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */
+#define BOOTCONFIG_FOOTER_SIZE \
+ (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN)
+
/**
* xbc_calc_checksum() - Calculate checksum of bootconfig
* @data: Bootconfig data.
--- a/init/main.c~b
+++ a/init/main.c
@@ -278,7 +278,7 @@ static void * __init get_boot_config_fro
int i;
if (!initrd_end || initrd_end < initrd_start ||
- initrd_end - initrd_start < BOOTCONFIG_MAGIC_LEN + 8)
+ initrd_end - initrd_start < BOOTCONFIG_FOOTER_SIZE)
return NULL;
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
--- a/tools/bootconfig/main.c~b
+++ a/tools/bootconfig/main.c
@@ -17,10 +17,6 @@
#define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
-/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */
-#define BOOTCONFIG_FOOTER_SIZE \
- (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN)
-
static void show_xbc_error(const char *data, const char *msg, int pos)
{
int lin = 1, col, i;
@@ -44,20 +40,12 @@ static void show_xbc_error(const char *d
static int init_xbc_with_error(char *buf, int len)
{
- char *copy = malloc(len);
const char *msg;
int ret, pos;
- if (!copy)
- return -ENOMEM;
-
- memcpy(copy, buf, len);
- /* We do not terminate the copy with \0 for sanity checking */
-
ret = xbc_init(buf, len, &msg, &pos);
if (ret < 0)
- show_xbc_error(copy, msg, pos);
- free(copy);
+ show_xbc_error(buf, msg, pos);
return ret;
}
_
On Fri, 11 Sep 2026 15:59:11 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:
> On Fri, 11 Sep 2026 23:12:56 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > Hi,
> >
> > Here are v2 patches for bootconfig to rejects unexpected config data after
> > null character and other cleanups including tools/bootconfig to consolidate
> > bootconfig initialization with errors, and skipping internal tree sanity
> > check in kernel.
> >
> > ...
> >
>
> Thanks, I've updateed mm.git's mm-nonmm-unstable branch to this version,
>
> > This version removes redundant buffer copy in init_xbc_with_error() [2/4]
> > and moves BOOTCONFIG_FOOTER_SIZE to include/linux/bootconfig.h[4/4].
OK, anyway I'll pick this series to bootconfig/for-next.
Thank you,
>
> Here's how v2 altered mm.git:
>
>
> include/linux/bootconfig.h | 4 ++++
> init/main.c | 2 +-
> tools/bootconfig/main.c | 14 +-------------
> 3 files changed, 6 insertions(+), 14 deletions(-)
>
> --- a/include/linux/bootconfig.h~b
> +++ a/include/linux/bootconfig.h
> @@ -27,6 +27,10 @@ bool __init cmdline_has_extra_options(vo
> #define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT)
> #define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1)
>
> +/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */
> +#define BOOTCONFIG_FOOTER_SIZE \
> + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN)
> +
> /**
> * xbc_calc_checksum() - Calculate checksum of bootconfig
> * @data: Bootconfig data.
> --- a/init/main.c~b
> +++ a/init/main.c
> @@ -278,7 +278,7 @@ static void * __init get_boot_config_fro
> int i;
>
> if (!initrd_end || initrd_end < initrd_start ||
> - initrd_end - initrd_start < BOOTCONFIG_MAGIC_LEN + 8)
> + initrd_end - initrd_start < BOOTCONFIG_FOOTER_SIZE)
> return NULL;
>
> data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
> --- a/tools/bootconfig/main.c~b
> +++ a/tools/bootconfig/main.c
> @@ -17,10 +17,6 @@
>
> #define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
>
> -/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */
> -#define BOOTCONFIG_FOOTER_SIZE \
> - (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN)
> -
> static void show_xbc_error(const char *data, const char *msg, int pos)
> {
> int lin = 1, col, i;
> @@ -44,20 +40,12 @@ static void show_xbc_error(const char *d
>
> static int init_xbc_with_error(char *buf, int len)
> {
> - char *copy = malloc(len);
> const char *msg;
> int ret, pos;
>
> - if (!copy)
> - return -ENOMEM;
> -
> - memcpy(copy, buf, len);
> - /* We do not terminate the copy with \0 for sanity checking */
> -
> ret = xbc_init(buf, len, &msg, &pos);
> if (ret < 0)
> - show_xbc_error(copy, msg, pos);
> - free(copy);
> + show_xbc_error(buf, msg, pos);
>
> return ret;
> }
> _
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
On Sat, 12 Sep 2026 22:48:35 +0900 Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > > > ... > > > > > > > Thanks, I've updateed mm.git's mm-nonmm-unstable branch to this version, > > > > > This version removes redundant buffer copy in init_xbc_with_error() [2/4] > > > and moves BOOTCONFIG_FOOTER_SIZE to include/linux/bootconfig.h[4/4]. > > OK, anyway I'll pick this series to bootconfig/for-next. Oh, I didn't know such a tree existed. No probs, I'll follow my usual automatic practice: if it appears in linux-next, I drop the mm.git copy. Often after checking that what-you-got matches what-i-got and if-not-why-not. I'm not a trusting soul ;)
© 2016 - 2026 Red Hat, Inc.