* [PATCH] panic: fix va_list reuse in panic_try_force_cpu()
@ 2026-07-05 16:41 Bradley Morgan
2026-07-05 19:10 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Bradley Morgan @ 2026-07-05 16:41 UTC (permalink / raw)
To: Andrew Morton, Feng Tang
Cc: Petr Mladek, Jinchao Wang, linux-kernel, Bradley Morgan
vsnprintf() consumes the caller's va_list. When the redirect fails,
vpanic() reuses it for the panic message, which is undefined
behavior. Use va_copy().
Signed-off-by: Bradley Morgan <include@grrlz.net>
---
kernel/panic.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/panic.c b/kernel/panic.c
index f9ad0250da67..03f1eef07b17 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -412,7 +412,12 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)
* fall back to static message for early boot panics or allocation failure.
*/
if (panic_force_buf) {
- vsnprintf(panic_force_buf, PANIC_MSG_BUFSZ, fmt, args);
+ va_list ap;
+
+ /* Do not consume args, the caller reuses it if we fail */
+ va_copy(ap, args);
+ vsnprintf(panic_force_buf, PANIC_MSG_BUFSZ, fmt, ap);
+ va_end(ap);
msg = panic_force_buf;
} else {
msg = "Redirected panic (buffer unavailable)";
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] panic: fix va_list reuse in panic_try_force_cpu()
2026-07-05 16:41 [PATCH] panic: fix va_list reuse in panic_try_force_cpu() Bradley Morgan
@ 2026-07-05 19:10 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2026-07-05 19:10 UTC (permalink / raw)
To: Bradley Morgan; +Cc: Feng Tang, Petr Mladek, Jinchao Wang, linux-kernel
On Sun, 5 Jul 2026 16:41:23 +0000 Bradley Morgan <include@grrlz.net> wrote:
> vsnprintf() consumes the caller's va_list. When the redirect fails,
> vpanic() reuses it for the panic message, which is undefined
> behavior. Use va_copy().
Thanks.
> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -412,7 +412,12 @@ static bool panic_try_force_cpu(const char *fmt, va_list args)
> * fall back to static message for early boot panics or allocation failure.
> */
> if (panic_force_buf) {
> - vsnprintf(panic_force_buf, PANIC_MSG_BUFSZ, fmt, args);
> + va_list ap;
> +
> + /* Do not consume args, the caller reuses it if we fail */
Nice comment!
> + va_copy(ap, args);
> + vsnprintf(panic_force_buf, PANIC_MSG_BUFSZ, fmt, ap);
> + va_end(ap);
> msg = panic_force_buf;
> } else {
> msg = "Redirected panic (buffer unavailable)";
AI review found a possible pre-existing thing in there (as usual,
sigh). Seems pretty improbable:
https://sashiko.dev/#/patchset/20260705164123.18746-1-include@grrlz.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-05 19:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-05 16:41 [PATCH] panic: fix va_list reuse in panic_try_force_cpu() Bradley Morgan
2026-07-05 19:10 ` Andrew Morton
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.