The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Masami Hiramatsu <mhiramat@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCH 2/4] bootconfig: Fix xbc_node_compose_key_after() for value nodes
Date: Sun, 22 Nov 2026 10:01:41 +0900	[thread overview]
Message-ID: <179530930140.109991.1418783350874051238.stgit@devnote2> (raw)
In-Reply-To: <179530928294.109991.3079999508446852151.stgit@devnote2>

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;


  parent reply	other threads:[~2026-11-22  1:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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) [this message]
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)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179530930140.109991.1418783350874051238.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox