TTY: ttyprintk, don't touch behind tty->write_buf
authorJiri Slaby <jslaby@suse.cz>
Tue, 7 Aug 2012 19:47:39 +0000 (21:47 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Aug 2012 20:29:57 +0000 (13:29 -0700)
If a user provides a buffer larger than a tty->write_buf chunk and
passes '\r' at the end of the buffer, we touch an out-of-bound memory.

Add a check there to prevent this.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: stable@vger.kernel.org (everything maintained past v2.6.37)
Cc: Samo Pogacnik <samo_pogacnik@t-2.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/ttyprintk.c

index 9b1e5e0cdc65736c61f58c4a09cb70e57a909f96..08755c52fc5f401fdee67abcb130bf0e82704bb5 100644 (file)
@@ -67,7 +67,7 @@ static int tpk_printk(const unsigned char *buf, int count)
                                tmp[tpk_curr + 1] = '\0';
                                printk(KERN_INFO "%s%s", tpk_tag, tmp);
                                tpk_curr = 0;
-                               if (buf[i + 1] == '\n')
+                               if ((i + 1) < count && buf[i + 1] == '\n')
                                        i++;
                                break;
                        case '\n':