* [PATCH 1/4] bootconfig: Fix xbc_verify_tree() to check subkeys of valued keys
2026-11-22 1:01 [PATCH 0/4] bootconfig: Fix tree verification, key composition, and cmdline rendering bugs Masami Hiramatsu (Google)
@ 2026-11-22 1:01 ` Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 2/4] bootconfig: Fix xbc_node_compose_key_after() for value nodes Masami Hiramatsu (Google)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-11-22 1:01 UTC (permalink / raw)
To: Masami Hiramatsu, Steven Rostedt, Andrew Morton
Cc: linux-kernel, linux-trace-kernel
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
When a key node has both a value and subkeys, the value node is always
inserted as the first child of the key node (xbc_add_head_sibling()), and
subkeys follow as next siblings of that value node.
However, xbc_verify_tree() uses xbc_node_get_child(n) and checks
xbc_node_is_key(m) to descend into subkeys. When a key node has a value,
xbc_node_get_child(n) returns the value node, so xbc_node_is_key(m) is
false and xbc_verify_tree() completely skips verifying all subkeys under
that key. This allows subkeys under a valued key to bypass both the
XBC_DEPTH_MAX (16) and XBC_KEYLEN_MAX (256) checks during xbc_init(),
causing runtime -ERANGE failures in xbc_node_compose_key_after().
Use xbc_node_get_subkey(n) so that subkeys of mixed value+subkey nodes
are properly verified.
Fixes: e5efaeb8a8f5 ("bootconfig: Support mixing a value and subkeys under a key")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
lib/bootconfig.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 948c8c10e4b9..026d88a65c5c 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -1058,8 +1058,8 @@ static int __init xbc_verify_tree(void)
return xbc_parse_error("Too long key length",
xbc_node_get_data(n));
- m = xbc_node_get_child(n);
- if (m && xbc_node_is_key(m)) {
+ m = xbc_node_get_subkey(n);
+ if (m) {
n = m;
depth++;
if (depth > XBC_DEPTH_MAX)
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/4] bootconfig: Fix xbc_node_compose_key_after() for value nodes
2026-11-22 1:01 [PATCH 0/4] bootconfig: Fix tree verification, key composition, and cmdline rendering bugs Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 1/4] bootconfig: Fix xbc_verify_tree() to check subkeys of valued keys Masami Hiramatsu (Google)
@ 2026-11-22 1:01 ` Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 3/4] bootconfig: Avoid out-of-bounds pointer arithmetic in xbc_snprint_cmdline_filter() Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 4/4] tools/bootconfig: Add tests for unclosed brace position and mixed-kv limits Masami Hiramatsu (Google)
3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-11-22 1:01 UTC (permalink / raw)
To: Masami Hiramatsu, Steven Rostedt, Andrew Morton
Cc: linux-kernel, linux-trace-kernel
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Fix two issues in xbc_node_compose_key_after() when @node is a value node:
1. Since array values are chained via the child pointer in
xbc_parse_array(), the 2nd and subsequent value nodes of an array have
the preceding value node as their parent rather than the owning key
node. Climbing only one parent (if (xbc_node_is_value(node))) caused
preceding array value strings to be included in the composed key
(e.g. "foo.bar.val1" instead of "foo.bar").
2. Checking `if (!node || node == root)` before climbing to the owning
key node allowed a value node belonging to the subtree @root key node
itself (e.g. `foo = "val"` with `@root = xbc_find_node("foo")`) to
pass the check, climb to @root, skip the key-collection loop
(depth == 0), and return 0 without writing anything (not even a NUL
terminator) to @buf.
Climb parent pointers in a loop while the node is a value node, and
perform the `if (!node || node == root)` check afterward.
Fixes: ca24306d83a1 ("bootconfig: Change array value to use child node")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
lib/bootconfig.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 026d88a65c5c..280b7e73321b 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -421,12 +421,12 @@ int __init xbc_node_compose_key_after(struct xbc_node *root,
uint16_t keys[XBC_DEPTH_MAX];
int depth = 0, ret = 0, total = 0;
+ while (node && xbc_node_is_value(node))
+ node = xbc_node_get_parent(node);
+
if (!node || node == root)
return -EINVAL;
- if (xbc_node_is_value(node))
- node = xbc_node_get_parent(node);
-
while (node && node != root) {
if (depth == XBC_DEPTH_MAX)
return -ERANGE;
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/4] bootconfig: Avoid out-of-bounds pointer arithmetic in xbc_snprint_cmdline_filter()
2026-11-22 1:01 [PATCH 0/4] bootconfig: Fix tree verification, key composition, and cmdline rendering bugs Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 1/4] bootconfig: Fix xbc_verify_tree() to check subkeys of valued keys Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 2/4] bootconfig: Fix xbc_node_compose_key_after() for value nodes Masami Hiramatsu (Google)
@ 2026-11-22 1:01 ` Masami Hiramatsu (Google)
2026-11-22 1:01 ` [PATCH 4/4] tools/bootconfig: Add tests for unclosed brace position and mixed-kv limits Masami Hiramatsu (Google)
3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-11-22 1:01 UTC (permalink / raw)
To: Masami Hiramatsu, Steven Rostedt, Andrew Morton
Cc: linux-kernel, linux-trace-kernel
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
xbc_snprint_cmdline_filter() passes `buf ? buf + len : NULL` to
snprintf(). While this avoids NULL pointer arithmetic when @buf is NULL,
if @buf is non-NULL and the rendered output exceeds @size (len > size),
evaluating `buf + len` forms a pointer past the end of the @buf
allocation, which is undefined behavior in C even though rest(len, size)
is 0.
Pass `buf && len < size ? buf + len : NULL` so that snprintf() receives
NULL whenever the remaining buffer capacity is 0.
Fixes: dec4d8118c17 ("bootconfig: fix NULL-pointer arithmetic in xbc_snprint_cmdline()")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
lib/bootconfig.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 280b7e73321b..9ae9a215b1da 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -587,8 +587,8 @@ int __init xbc_snprint_cmdline_filter(char *buf, size_t size, struct xbc_node *r
vnode = xbc_node_get_child(knode);
if (!vnode) {
- ret = snprintf(buf ? buf + len : NULL, rest(len, size),
- "%s ", xbc_namebuf);
+ ret = snprintf(buf && len < size ? buf + len : NULL,
+ rest(len, size), "%s ", xbc_namebuf);
if (ret < 0)
return ret;
len += ret;
@@ -601,7 +601,8 @@ int __init xbc_snprint_cmdline_filter(char *buf, size_t size, struct xbc_node *r
* whitespace.
*/
q = strpbrk(val, " \t\r\n") ? "\"" : "";
- ret = snprintf(buf ? buf + len : NULL, rest(len, size),
+ ret = snprintf(buf && len < size ? buf + len : NULL,
+ rest(len, size),
"%s=%s%s%s ", xbc_namebuf, q, val, q);
if (ret < 0)
return ret;
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 4/4] tools/bootconfig: Add tests for unclosed brace position and mixed-kv limits
2026-11-22 1:01 [PATCH 0/4] bootconfig: Fix tree verification, key composition, and cmdline rendering bugs Masami Hiramatsu (Google)
` (2 preceding siblings ...)
2026-11-22 1:01 ` [PATCH 3/4] bootconfig: Avoid out-of-bounds pointer arithmetic in xbc_snprint_cmdline_filter() Masami Hiramatsu (Google)
@ 2026-11-22 1:01 ` Masami Hiramatsu (Google)
3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-11-22 1:01 UTC (permalink / raw)
To: Masami Hiramatsu, Steven Rostedt, Andrew Morton
Cc: linux-kernel, linux-trace-kernel
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Add regression test cases to test-bootconfig.sh for:
1. Unclosed brace error position reporting in xbc_verify_tree()
(verifying both samples/bad-tree.bconf and a multi-block config).
2. XBC_DEPTH_MAX (16) and XBC_KEYLEN_MAX (256) enforcement on subkeys
under a key node that also has a value (mixed value+subkey).
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
tools/bootconfig/test-bootconfig.sh | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
index f584f7637e12..6b396dea9095 100755
--- a/tools/bootconfig/test-bootconfig.sh
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -220,6 +220,39 @@ xpass $BOOTCONF -a $TEMPCONF $INITRD
$BOOTCONF $INITRD > $OUTFILE
xpass grep -q "value" $OUTFILE
+echo "Unclosed brace error position"
+cat > $TEMPCONF << EOF
+a {
+ b = 1
+}
+c {
+ d = 2
+EOF
+echo > $INITRD
+
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
+xpass grep -q "Brace.is.not.closed.at.4:1" $OUTFILE
+$BOOTCONF -a samples/bad-tree.bconf $INITRD > $OUTFILE 2>&1
+xpass grep -q "Brace.is.not.closed.at.2:1" $OUTFILE
+
+echo "Mixed value and subkey depth/length limits"
+cat > $TEMPCONF << EOF
+k1 = v1
+k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17 = v2
+EOF
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+
+awk '
+BEGIN {
+ printf("root = v\nroot.")
+ for (i = 0; i < 255; i += 1)
+ printf("a")
+ printf(" = v2\n")
+}
+' > $TEMPCONF
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+
echo "=== expected failure cases ==="
for i in samples/bad-* ; do
xfail $BOOTCONF -a $i $INITRD
^ permalink raw reply related [flat|nested] 5+ messages in thread