Skip to content

Commit 988a35f

Browse files
Tetsuo Handapmladek
authored andcommitted
printk: fix possible reuse of va_list variable
I noticed that there is a possibility that printk_safe_log_store() causes kernel oops because "args" parameter is passed to vsnprintf() again when atomic_cmpxchg() detected that we raced. Fix this by using va_copy(). Link: http://lkml.kernel.org/r/[email protected] Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Tetsuo Handa <[email protected]> Fixes: 42a0bb3 ("printk/nmi: generic solution for safe printk in NMI") Cc: 4.7+ <[email protected]> # v4.7+ Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Petr Mladek <[email protected]>
1 parent 43a1711 commit 988a35f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

kernel/printk/printk_safe.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
8282
{
8383
int add;
8484
size_t len;
85+
va_list ap;
8586

8687
again:
8788
len = atomic_read(&s->len);
@@ -100,7 +101,9 @@ static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
100101
if (!len)
101102
smp_rmb();
102103

103-
add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args);
104+
va_copy(ap, args);
105+
add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, ap);
106+
va_end(ap);
104107
if (!add)
105108
return 0;
106109

0 commit comments

Comments
 (0)