From: Jiri Slaby <jslaby@suse.cz>
Date: Tue, 7 Aug 2012 19:47:39 +0000 (+0200)
Subject: TTY: ttyprintk, don't touch behind tty->write_buf
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ee8b593affdf893012e57f4c54a21984d1b0d92e;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git

TTY: ttyprintk, don't touch behind tty->write_buf

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>
---

diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index 9b1e5e0cdc65..08755c52fc5f 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -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':