Re: [RFC PATCH 2/5] bootconfig: Support stacked initrd bootconfigs and bootconfig= selection

From
sashiko-bot@kernel.org
Date
2026-11-27 15:11:06
Reply to
Masami Hiramatsu (Google), 2026-11-27
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bootconfig: unmatched bootconfig= selector bypasses
  CONFIG_BOOT_CONFIG_FORCE
- [Low] bootconfig: wrong config blamed for unclosed brace in
  xbc_parse_tree()
--

commit d486115d0ecb79c7d4d59dbde4c3a203ebf39848
Author: Masami Hiramatsu (Google) [off-list ref]

bootconfig: Support stacked initrd bootconfigs and bootconfig= selection

This commit adds support for unpacking up to 32 stacked bootconfig trailers
from an initrd image and selecting which entries to merge via the
bootconfig= kernel command-line parameter.
quoted hunk ↗ jump to hunk
diff --git a/init/main.c b/init/main.c
index f147803450513..a539eb5b0cd12 100644
--- a/init/main.c
+++ b/init/main.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -475,16 +575,35 @@ static void __init setup_boot_config(void)
 		return;
 	}
 
-	ret = xbc_init(data, size, &msg, &pos);
+	report_bad_boot_configs(cfgs, count, total);
+
+	if (!bootconfig_found && IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE))
+		cfgs[0].enabled = true;
+
+	for (i = 0; i < count; i++) {
+		if (cfgs[i].enabled && cfgs[i].data) {
+			any_enabled = true;
+			break;
+		}
+	}
+	if (!any_enabled)
+		return;
+
+	ret = xbc_init_configs(cfgs, count, &msg, &pos, &err_idx);
 	if (ret < 0) {
-		if (pos < 0)
+		if (err_idx >= 0)
+			pr_err("Failed to parse bootconfig [%d%s%.*s]: %s at %d.\n",
+			       err_idx, cfgs[err_idx].name_len ? ":" : "",
+			       (int)cfgs[err_idx].name_len,
+			       cfgs[err_idx].name, msg, pos);
[Severity: Low]
Can this blame an earlier bootconfig block when a later overlay leaves a
brace unclosed on an existing key?

When an overlay reopens a key that was already created by an earlier
block, __xbc_add_key() reuses the existing xbc_node via find_match_node()
and __xbc_open_brace() pushes that node's index onto open_brace[].  If the
brace is left unclosed at the end of the overlay, xbc_parse_tree() reports
the error at xbc_node_get_data(n):

lib/bootconfig.c:xbc_parse_tree() {
    ...
	if (!ret && brace_index) {
		n = &xbc_nodes[open_brace[brace_index - 1]];
		ret = xbc_parse_error("Brace is not closed",
				      xbc_node_get_data(n));
	}
    ...
}

Because xbc_node_get_data(n) points into the slice that first defined the
key, xbc_init_configs() maps xbc_err_pos back to that earlier block's
err_idx and byte offset.
quoted hunk ↗ jump to hunk
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index fe27e72c9ee54..44177b7c08660 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -115,33 +115,54 @@ bool __init xbc_embedded_cmdline_applied(void)
 }
 #endif	/* CONFIG_CMDLINE_FROM_BOOTCONFIG */
 
-/* parse_args() callback: flag when the "bootconfig" parameter is present. */
-static int __init bootconfig_optin(char *param, char *val,
-				   const char *unused, void *arg)
+struct xbc_cmdline_select_ctx {
+	struct xbc_config *cfgs;
+	int count;
+	bool seen;
+	bool active;
+	bool warn;
+};
+
+/* parse_args() callback: track opt-in and update enabled bootconfig entries. */
+static int __init xbc_cmdline_select_cb(char *param, char *val,
+					const char *unused, void *arg)
 {
-	if (!strcmp(param, "bootconfig"))
-		*(bool *)arg = true;
+	struct xbc_cmdline_select_ctx *ctx = arg;
+
+	if (strcmp(param, "bootconfig"))
+		return 0;
+
+	if (!val) {
+		ctx->active = true;
+	} else if (*val == '\0') {
+		ctx->active = false;
+	} else if (*val == '+') {
+		if (!ctx->seen || val[1] != '\0')
+			ctx->active = true;
+	} else {
+		ctx->active = true;
+	}
+
+	if (ctx->cfgs)
+		__xbc_enable_configs(ctx->cfgs, ctx->count, val,
+				     &ctx->seen, ctx->warn);
+	else
+		ctx->seen = true;
+
 	return 0;
 }
[ ... ]
quoted hunk ↗ jump to hunk
+bool __init bootconfig_cmdline_requested(const char *boot_cmdline, int *end_offset)
+{
+	struct xbc_config emb = { .name = "", .name_len = 0, .enabled = false };
+	const char *data;
+	size_t size;
+	bool active;
+
+	data = xbc_get_embedded_bootconfig(&size);
+	if (data && xbc_parse_id_header(data, size, &emb) < 0) {
+		emb.name = "";
+		emb.name_len = 0;
+	}
+
+	active = xbc_parse_cmdline_bootconfig(boot_cmdline, &emb, 1,
+					      end_offset, false);
+	if (IS_ENABLED(CONFIG_BOOT_CONFIG_FORCE) && !active)
+		return true;
+
+	return active && emb.enabled;
+}
[Severity: Medium]
Does an unmatched bootconfig=<sel> parameter bypass
CONFIG_BOOT_CONFIG_FORCE=y instead of falling back to index 0?

xbc_cmdline_select_cb() sets ctx->active = true for any non-empty val even
when __xbc_enable_configs() finds no matching entry and leaves every
cfgs[i].enabled set to false.  Because active (and bootconfig_found in
setup_boot_config()) is true while no config is enabled, the
CONFIG_BOOT_CONFIG_FORCE fallback (!active / !bootconfig_found) is skipped
in both bootconfig_cmdline_requested() and setup_boot_config(), so no
bootconfig is applied at all.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127144614.61194-1-mhiramat@kernel.org?part=2
Thread (10 messages) 10 messages, 2 authors, last reply 20h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help