All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cli: hush_modern: fix use after free of argv in pipelines
@ 2026-12-03 22:32 Yuho Choi
  0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-12-03 22:32 UTC (permalink / raw)
  To: Tom Rini; +Cc: Francis Laniel, Anshul Dalal, u-boot, Yuho Choi

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04  0:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 22:32 [PATCH] cli: hush_modern: fix use after free of argv in pipelines Yuho Choi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.