From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Andrew Morton <akpm@linux-foundation.org>,
Jiri Kosina <jkosina@suse.cz>,
Randy Dunlap <rdunlap@infradead.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] lib/vsprintf.c: Don't try to fix pointer wrap-around
Date: Thu, 8 Jan 2015 13:14:46 +0100 [thread overview]
Message-ID: <1420719287-10222-3-git-send-email-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <1420719287-10222-1-git-send-email-linux@rasmusvillemoes.dk>
Actual kernel buffers can't wrap into the user address space. If
someone manages to pass a buf/size combination that wraps, it is most
likely due to a bug in the caller. Instead of trying to fix it by
using a smaller part of the buffer, bail out.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/vsprintf.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index cf12ba86205c..1ec6a78f169b 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1733,11 +1733,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
str = buf;
end = buf + size;
- /* Make sure end is always >= buf */
- if (end < buf) {
- end = ((void *)-1);
- size = end - buf;
- }
+ /* Also bail out if buf+size wraps */
+ if (WARN_ON_ONCE(end < buf))
+ return 0;
while (*fmt) {
const char *old_fmt = fmt;
--
2.1.3
next prev parent reply other threads:[~2015-01-08 12:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-08 12:14 [PATCH 1/4] lib/vsprintf.c: Consume 'p' in format_decode Rasmus Villemoes
2015-01-08 12:14 ` [PATCH 2/4] lib/vsprintf.c: Improve sanity check in vsnprintf() Rasmus Villemoes
2015-01-08 12:14 ` Rasmus Villemoes [this message]
2015-01-08 12:14 ` [PATCH 4/4] lib/vsprintf.c: Replace while with do-while in skip_atoi Rasmus Villemoes
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=1420719287-10222-3-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.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
all inboxes | Powered by JetHome®