From: Jeff Mahoney <jeffm@suse.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Kay Sievers <kay@vrfy.org>
Cc: stable@kernel.org,
Linux Kernel Maling List <linux-kernel@vger.kernel.org>
Subject: [PATCH] printk: Fix calculation of length used to discard records
Date: Fri, 10 Aug 2012 15:07:09 -0400 [thread overview]
Message-ID: <50255BDD.2070508@suse.com> (raw)
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 0.
This patch properly accounts for it and fixes the overflow.
CC: stable@kernel.org
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
kernel/printk.c | 2 ++
1 file changed, 2 insertions(+)
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1034,6 +1034,7 @@ static int syslog_print_all(char __user
struct log *msg = log_from_idx(idx);
len += msg_print_text(msg, prev, true, NULL, 0);
+ prev = msg->flags;
idx = log_next(idx);
seq++;
}
@@ -1046,6 +1047,7 @@ static int syslog_print_all(char __user
struct log *msg = log_from_idx(idx);
len -= msg_print_text(msg, prev, true, NULL, 0);
+ prev = msg->flags;
idx = log_next(idx);
seq++;
}
--
Jeff Mahoney
SUSE Labs
reply other threads:[~2012-08-10 19:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50255BDD.2070508@suse.com \
--to=jeffm@suse.com \
--cc=kay@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox