4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Tetsuo Handa <penguin-ker...@i-love.sakura.ne.jp>

commit 988a35f8da1dec5a8cd2788054d1e717be61bf25 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/201805112002.gif21216.ofvhfomljtq...@i-love.sakura.ne.jp
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Steven Rostedt <rost...@goodmis.org>
Cc: dvyu...@google.com
Cc: syzkal...@googlegroups.com
Cc: fengguang...@intel.com
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Tetsuo Handa <penguin-ker...@i-love.sakura.ne.jp>
Fixes: 42a0bb3f71383b45 ("printk/nmi: generic solution for safe printk in NMI")
Cc: 4.7+ <sta...@vger.kernel.org> # v4.7+
Reviewed-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>
Signed-off-by: Petr Mladek <pmla...@suse.com>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 kernel/printk/nmi.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/kernel/printk/nmi.c
+++ b/kernel/printk/nmi.c
@@ -63,6 +63,7 @@ static int vprintk_nmi(const char *fmt,
        struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
        int add = 0;
        size_t len;
+       va_list ap;
 
 again:
        len = atomic_read(&s->len);
@@ -79,7 +80,9 @@ again:
        if (!len)
                smp_rmb();
 
-       add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args);
+       va_copy(ap, args);
+       add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, ap);
+       va_end(ap);
 
        /*
         * Do it once again if the buffer has been flushed in the meantime.


Reply via email to