diff options
| author | Breno Leitao <leitao@debian.org> | 2026-07-02 21:15:44 +0900 |
|---|---|---|
| committer | Masami Hiramatsu (Google) <mhiramat@kernel.org> | 2026-07-02 21:15:44 +0900 |
| commit | 7afe198fc1edffcda3bc82b13eed2e5f576b60a4 (patch) | |
| tree | 4c62690c944c277b28385cd18da631360bf39dbc /lib | |
| parent | 4a50a141f05a8d1737661b19ee22ff8455b94409 (diff) | |
| download | linux-7afe198fc1edffcda3bc82b13eed2e5f576b60a4.tar.gz linux-7afe198fc1edffcda3bc82b13eed2e5f576b60a4.zip | |
bootconfig: render descendant keys when xbc_snprint_cmdline() root has a value
xbc_node_for_each_key_value() walks to the first leaf under @root, and
when @root is itself a leaf it yields @root. That happens not only for
an empty "kernel {}" subtree, but also when @root carries both a value
and subkeys, e.g.
kernel = x
kernel.foo = bar
Here @root ("kernel") is a leaf because its first child is the value
node "x", so the iterator returns @root first. Feeding @root back into
xbc_node_compose_key_after(root, root) returns -EINVAL, which the only
in-kernel caller papers over with a "len <= 0" check -- but the
follow-up tools/bootconfig -C user propagates the error and turns such
a bootconfig into a build failure. Worse, short-circuiting the whole
call on a leaf @root would silently drop the valid "kernel.foo = bar"
descendant that this patch should render.
Skip @root inside the loop instead of bailing out: the value-only entry
is dropped (it is rendered through the "kernel" cmdline path, not here),
while real descendant keys are still emitted. An entirely empty subtree
now renders nothing and returns 0 rather than -EINVAL, matching the
"nothing to render is not an error" semantics expected by the new
build-time caller.
Link: https://lore.kernel.org/all/20260626-bootconfig_using_tools-v7-2-24ab72139c29@debian.org/
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bootconfig.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 2ed9ee3dc81c..926094d97397 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -440,6 +440,17 @@ int __init xbc_snprint_cmdline(char *buf, size_t size, struct xbc_node *root) * itself is well defined and returns the would-be length. */ xbc_node_for_each_key_value(root, knode, val) { + /* + * An empty or value-only @root (e.g. "kernel {}" or + * "kernel = x", possibly alongside "kernel.foo = bar") + * yields @root itself here. Skip it: composing a key for it + * would fail with -EINVAL, yet any real descendant keys must + * still be rendered. An entirely empty subtree then renders + * nothing and returns 0 rather than an error. + */ + if (knode == root) + continue; + ret = xbc_node_compose_key_after(root, knode, xbc_namebuf, XBC_KEYLEN_MAX); if (ret < 0) |
