From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Josh Law <hlcj1234567@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Josh Law <objecting@objecting.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] lib/bootconfig: fix off-by-one in xbc_verify_tree() unclosed brace error
Date: Fri, 13 Mar 2026 10:39:00 +0900 [thread overview]
Message-ID: <20260313103900.d2d0ff8ccd6179b8decbe0b9@kernel.org> (raw)
In-Reply-To: <48aee348-5859-4d13-aa88-d0c21a4c0289@gmail.com>
On Thu, 12 Mar 2026 21:03:52 +0000
Josh Law <hlcj1234567@gmail.com> wrote:
> 12 Mar 2026 21:02:51 Steven Rostedt <rostedt@goodmis.org>:
>
> > On Thu, 12 Mar 2026 19:11:41 +0000
> > Josh Law <hlcj1234567@gmail.com> wrote:
> >
> >> From: Josh Law <objecting@objecting.org>
> >>
> >> __xbc_open_brace() pushes entries with post-increment
> >> (open_brace[brace_index++]), so brace_index always points one past
> >> the last valid entry. xbc_verify_tree() reads open_brace[brace_index]
> >> to report which brace is unclosed, but this is one past the last
> >> pushed entry and contains stale/zero data, causing the error message
> >> to reference the wrong node.
> >>
> >> Use open_brace[brace_index - 1] to correctly identify the unclosed
> >> brace. brace_index is known to be > 0 here since we are inside the
> >> if (brace_index) guard.
> >>
> >> Signed-off-by: Josh Law <objecting@objecting.org>
> >
> > Nice catch. May I ask how you found this.
> >
> > Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Thanks for patch and review!
> >
> > -- Steve
> >
> >> ---
> >> lib/bootconfig.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/lib/bootconfig.c b/lib/bootconfig.c
> >> index 2bcd5c2aa87e..a1e6a2e14b01 100644
> >> --- a/lib/bootconfig.c
> >> +++ b/lib/bootconfig.c
> >> @@ -802,7 +802,7 @@ static int __init xbc_verify_tree(void)
> >>
> >> /* Brace closing */
> >> if (brace_index) {
> >> - n = &xbc_nodes[open_brace[brace_index]];
> >> + n = &xbc_nodes[open_brace[brace_index - 1]];
> >> return xbc_parse_error("Brace is not closed",
> >> xbc_node_get_data(n));
> >> }
>
> Hi Steve,
> Thanks for the review!
> I found this while doing a manual audit of the bootconfig parser's error handling. I noticed that the post-increment in __xbc_open_brace() didn't seem to align with how xbc_verify_tree() was accessing the index. I verified it by intentionally passing a
malformed config with an unclosed brace and saw it reporting a 'stale' or incorrect node location
Thanks, I confirmed it with below config.
$ cat samples/bad-non-closed-brace.bconf
foo {
bar {
buz
}
This closed the 2nd `{`, but not close the first one.
Without patch;
$ ./bootconfig samples/bad-non-closed-brace.bconf
Parse Error: Brace is not closed at 2:2
With this fix;
$ ./bootconfig samples/bad-non-closed-brace.bconf
Parse Error: Brace is not closed at 1:1
Than you!
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-03-13 1:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 19:11 [PATCH v2 0/3] lib/bootconfig: three bug fixes Josh Law
2026-03-12 19:11 ` [PATCH v2 1/3] lib/bootconfig: fix off-by-one in xbc_verify_tree() unclosed brace error Josh Law
2026-03-12 21:03 ` Steven Rostedt
2026-03-12 21:03 ` Josh Law
2026-03-13 1:39 ` Masami Hiramatsu [this message]
2026-03-12 19:11 ` [PATCH v2 2/3] lib/bootconfig: check bounds before writing in __xbc_open_brace() Josh Law
2026-03-12 21:06 ` Steven Rostedt
2026-03-12 21:08 ` Josh Law
2026-03-12 21:09 ` Josh Law
2026-03-12 21:28 ` Andrew Morton
2026-03-12 21:30 ` Josh Law
2026-03-12 21:47 ` Steven Rostedt
2026-03-13 4:18 ` Masami Hiramatsu
2026-03-13 2:10 ` Masami Hiramatsu
2026-03-12 19:11 ` [PATCH v2 3/3] lib/bootconfig: fix snprintf truncation check in xbc_node_compose_key_after() Josh Law
2026-03-12 21:09 ` Steven Rostedt
2026-03-13 2:26 ` Masami Hiramatsu
2026-03-13 4:18 ` [PATCH] bootconfig: Add bootconfig tests about braces Masami Hiramatsu (Google)
2026-03-13 7:10 ` Josh Law
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=20260313103900.d2d0ff8ccd6179b8decbe0b9@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hlcj1234567@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=objecting@objecting.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