[PATCH v5 3/4] panic: fix va_list reuse in panic_try_force_cpu()
From: Bradley Morgan
Date: Sun Jul 26 2026 - 15:04:43 EST
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().
Fixes: 2e171ab29f91 ("panic: add panic_force_cpu= parameter to redirect panic to a specific CPU")
Cc: stable@xxxxxxxxxxxxxxx
Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
Signed-off-by: Bradley Morgan <include@xxxxxxxxx>
---
kernel/panic.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/panic.c b/kernel/panic.c
index 74065c860779..a483587fdd2f 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -416,7 +416,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.47.3