printk: fix possible printk overrun
authorTejun Heo <htejun@gmail.com>
Thu, 14 Feb 2008 01:32:07 +0000 (10:32 +0900)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 26 Feb 2008 15:42:37 +0000 (07:42 -0800)
printk recursion detection prepends message to printk_buf and offsets
printk_buf when actual message is printed but it forgets to trim buffer
length accordingly. This can result in overrun in extreme cases. Fix it.

[ mingo@elte.hu:

  bug was introduced by me via:

   commit 32a76006683f7b28ae3cc491da37716e002f198e
   Author: Ingo Molnar <mingo@elte.hu>
   Date:   Fri Jan 25 21:07:58 2008 +0100

       printk: make printk more robust by not allowing recursion
]

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/printk.c

index bee36100f110ab75617ad4dce16beac9e1434f76..9adc2a473e6e0f59bbc41350422d415e8f17a7ec 100644 (file)
@@ -666,7 +666,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
        }
        /* Emit the output into the temporary buffer */
        printed_len += vscnprintf(printk_buf + printed_len,
-                                 sizeof(printk_buf), fmt, args);
+                                 sizeof(printk_buf) - printed_len, fmt, args);
 
        /*
         * Copy the output into log_buf.  If the caller didn't provide