Skip to content

Commit a47c3c4

Browse files
Tetsuo Handagregkh
authored andcommitted
printk: fix possible reuse of va_list variable
commit 988a35f upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent affd840 commit a47c3c4

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
@@ -85,6 +85,7 @@ static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
8585
{
8686
int add;
8787
size_t len;
88+
va_list ap;
8889

8990
again:
9091
len = atomic_read(&s->len);
@@ -103,7 +104,9 @@ static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
103104
if (!len)
104105
smp_rmb();
105106

106-
add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args);
107+
va_copy(ap, args);
108+
add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, ap);
109+
va_end(ap);
107110
if (!add)
108111
return 0;
109112

0 commit comments

Comments
 (0)