From: Yuho Choi <oss.patchbox@gmail.com>
To: Tom Rini <trini@konsulko.com>
Cc: Francis Laniel <francis.laniel@amarulasolutions.com>,
Anshul Dalal <anshuld@ti.com>,
u-boot@lists.u-boot-project.org,
Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] cli: hush_modern: fix use after free of argv in pipelines
Date: Thu, 3 Dec 2026 22:32:43 +0000 [thread overview]
Message-ID: <20261203223248.2332373-2-oss.patchbox@gmail.com> (raw)
run_pipe() frees argv_expanded after each command but does not clear
it. In a pipeline such as "echo a | echo b", the next member then runs
with the freed argv and frees it a second time, which corrupts the
heap. Renesas R-Car boards use the modern parser, so typing a '|' at
their prompt is enough to hit this.
Clear the pointer after freeing it, as the non-U-Boot path does.
Fixes: 74e425407f1c ("cli: hush_modern: Enable variables expansion for modern hush")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
An LLM helped write and run this reproduction test.
Tested on sandbox (origin/main d1caced3a43) with only the modern parser
enabled, as in renesas_rcar.config, running
'echo first | echo second; echo after':
Before:
with UNIT_TEST: "first", then "Unknown command '' - try 'help'",
then "common/dlmalloc.c:816: do_check_inuse_chunk:
Assertion `inuse(p)' failed."
without UNIT_TEST: the second member is a garbage command name, and
U-Boot then hangs until the sandbox watchdog fires
(3 of 3 runs)
After:
"first", "second", "after" in both builds.
'ut hush' passes (22 tests) before and after. Pipe members after the
first are still run without variable expansion; I left that alone, as
U-Boot has no real pipes and the old parser does not run them at all.
common/cli_hush_upstream.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index c01ba00e475..f2406df5c31 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -10349,6 +10349,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
* argv, we need to free it.
*/
free(argv_expanded);
+ argv_expanded = NULL;
/*
* We also restore command->argv to its original value
base-commit: d1caced3a435607435cb7969e34499051a4ac1e6
--
2.56.1
reply other threads:[~2026-12-04 0:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261203223248.2332373-2-oss.patchbox@gmail.com \
--to=oss.patchbox@gmail.com \
--cc=anshuld@ti.com \
--cc=francis.laniel@amarulasolutions.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.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