From: Jan Kara <jack@suse.cz>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 2/2] lib: Limit strnlen_user() return value to count + 1
Date: Tue, 2 Jun 2015 17:10:29 +0200 [thread overview]
Message-ID: <1433257829-1743-2-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1433257829-1743-1-git-send-email-jack@suse.cz>
Currently strnlen_user() can return numbers between 0 and
count + sizeof(unsigned long) - 1. Currently, no in tree users seem to
care but I have found out of tree users which were broken by this. They
wanted to truncate the string if it was too long to fit into a buffer
and didn't count with the fact that strnlen_user() can return more.
So make the function harder to use wrong and return count + 1 max.
CC: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
lib/strnlen_user.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
index fd03ae980013..2e47f9e16a79 100644
--- a/lib/strnlen_user.c
+++ b/lib/strnlen_user.c
@@ -54,7 +54,10 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count,
if (has_zero(c, &data, &constants)) {
data = prep_zero_mask(c, data, &constants);
data = create_zero_mask(data);
- return res + find_zero(data) + 1 - align;
+ res = res + find_zero(data) + 1 - align;
+ if (res > count)
+ return count + 1;
+ return res;
}
res += sizeof(unsigned long);
if (unlikely(max <= sizeof(unsigned long)))
--
2.1.4
next prev parent reply other threads:[~2015-06-02 15:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-02 15:10 [PATCH 1/2] lib: Fix strnlen_user() to not touch memory after specified maximum Jan Kara
2015-06-02 15:10 ` Jan Kara [this message]
2015-06-02 17:08 ` [PATCH 2/2] lib: Limit strnlen_user() return value to count + 1 Linus Torvalds
2015-06-03 9:21 ` Jan Kara
2015-06-03 13:21 ` Linus Torvalds
2015-06-03 13:42 ` Jan Kara
2015-06-02 17:10 ` [PATCH 1/2] lib: Fix strnlen_user() to not touch memory after specified maximum Linus Torvalds
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=1433257829-1743-2-git-send-email-jack@suse.cz \
--to=jack@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®