Update to 3.6-rc2. - Eliminated 2 patches.
[opensuse:kernel-source.git] / patches.fixes / printk-fix-calculation-of-length-used-to-discard-records
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
4
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:
9
10 11339 syslog(SYSLOG_ACTION_READ_ALL, "<5>[244017.708129] REISERFS (dev"..., 8192) = 8279
11
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
15 is passed as 0.
16
17 This patch properly accounts for it and fixes the overflow.
18
19 CC: stable@kernel.org
20 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
21 ---
22  kernel/printk.c |    2 ++
23  1 file changed, 2 insertions(+)
24
25 --- a/kernel/printk.c
26 +++ b/kernel/printk.c
27 @@ -1034,6 +1034,7 @@ static int syslog_print_all(char __user
28                         struct log *msg = log_from_idx(idx);
29  
30                         len += msg_print_text(msg, prev, true, NULL, 0);
31 +                       prev = msg->flags;
32                         idx = log_next(idx);
33                         seq++;
34                 }
35 @@ -1046,6 +1047,7 @@ static int syslog_print_all(char __user
36                         struct log *msg = log_from_idx(idx);
37  
38                         len -= msg_print_text(msg, prev, true, NULL, 0);
39 +                       prev = msg->flags;
40                         idx = log_next(idx);
41                         seq++;
42                 }