summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2012-08-10 15:07:09 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-15 07:53:03 -0700
commit6fd9636dc32ee59c03434a3c6044b41621d806e8 (patch)
tree98d9a080dc90517d0345b965a058e1914a2adf0f
parent9b9efe7459c14ccb49e87f1bc46289a9a26e8602 (diff)
downloadlwn-6fd9636dc32ee59c03434a3c6044b41621d806e8.tar.gz
lwn-6fd9636dc32ee59c03434a3c6044b41621d806e8.zip
printk: Fix calculation of length used to discard records
commit e3756477aec028427fec767957c0d4b6cfb87208 upstream. While tracking down a weird buffer overflow issue in a program that looked to be sane, I started double checking the length returned by syslog(SYSLOG_ACTION_READ_ALL, ...) to make sure it wasn't overflowing the buffer. Sure enough, it was. I saw this in strace: 11339 syslog(SYSLOG_ACTION_READ_ALL, "<5>[244017.708129] REISERFS (dev"..., 8192) = 8279 It turns out that the loops that calculate how much space the entries will take when they're copied don't include the newlines and prefixes that will be included in the final output since prev flags is passed as zero. This patch properly accounts for it and fixes the overflow. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--kernel/printk.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/printk.c b/kernel/printk.c
index 21bea76a9fff..146827f81a06 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -999,6 +999,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
struct log *msg = log_from_idx(idx);
len += msg_print_text(msg, prev, true, NULL, 0);
+ prev = msg->flags;
idx = log_next(idx);
seq++;
}
@@ -1011,6 +1012,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
struct log *msg = log_from_idx(idx);
len -= msg_print_text(msg, prev, true, NULL, 0);
+ prev = msg->flags;
idx = log_next(idx);
seq++;
}