From: Kees Cook <keescook@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Joe Perches <joe@perches.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Yann Droneaud <ydroneaud@opteya.com>,
David Laight <David.Laight@aculab.com>,
Jonathan Corbet <corbet@lwn.net>, Stephen Kitt <steve@sk2.org>,
Nitin Gote <nitin.r.gote@intel.com>,
"jannh@google.com" <jannh@google.com>,
kernel-hardening@lists.openwall.com,
linux-kernel@vger.kernel.org
Subject: [PATCH] strscpy: reject buffer sizes larger than INT_MAX
Date: Fri, 26 Jul 2019 09:31:03 -0700 [thread overview]
Message-ID: <201907260928.23DE35406@keescook> (raw)
As already done for snprintf(), add a check in strscpy() for giant
(i.e. likely negative and/or miscalculated) copy sizes, WARN, and
error out.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
lib/string.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/string.c b/lib/string.c
index 461fb620f85f..913cb945a82a 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -182,7 +182,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
size_t max = count;
long res = 0;
- if (count == 0)
+ if (count == 0 || WARN_ON_ONCE(count > INT_MAX))
return -E2BIG;
#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
--
2.17.1
--
Kees Cook
reply other threads:[~2019-07-26 16:31 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=201907260928.23DE35406@keescook \
--to=keescook@chromium.org \
--cc=David.Laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=jannh@google.com \
--cc=joe@perches.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=nitin.r.gote@intel.com \
--cc=steve@sk2.org \
--cc=torvalds@linux-foundation.org \
--cc=ydroneaud@opteya.com \
/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