1 From: Jeff Mahoney <jeffm@suse.com>
2 Subject: printk: Fix calculation of length used to discard records
3 Patch-mainline: Submitted to LKML 10 Aug 2012
5 While tracking down a weird buffer overflow issue in a program that
6 looked to be sane, I started double checking the length returned
7 by syslog(SYSLOG_ACTION_READ_ALL, ...) to make sure it wasn't overflowing
8 the buffer. Sure enough, it was. I saw this in strace:
10 11339 syslog(SYSLOG_ACTION_READ_ALL, "<5>[244017.708129] REISERFS (dev"..., 8192) = 8279
12 It turns out that the loops that calculate how much space the entries
13 will take when they're copied don't include the newlines and
14 prefixes that will be included in the final output since prev flags
17 This patch properly accounts for it and fixes the overflow.
20 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
22 kernel/printk.c | 2 ++
23 1 file changed, 2 insertions(+)
27 @@ -1034,6 +1034,7 @@ static int syslog_print_all(char __user
28 struct log *msg = log_from_idx(idx);
30 len += msg_print_text(msg, prev, true, NULL, 0);
35 @@ -1046,6 +1047,7 @@ static int syslog_print_all(char __user
36 struct log *msg = log_from_idx(idx);
38 len -= msg_print_text(msg, prev, true, NULL, 0);