strscpy: reject buffer sizes larger than INT_MAX
authorKees Cook <keescook@chromium.org>
Wed, 25 Sep 2019 23:46:20 +0000 (16:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 26 Sep 2019 00:51:39 +0000 (17:51 -0700)
commit9a156466147b61504f4cbe97ea503e67c21e117a
tree25f41cd13e244c58bdf536c601225a05daa4caa9
parentd1a445d3b86c9341ce7a0954c23be0edb5c9bec5
strscpy: reject buffer sizes larger than INT_MAX

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.

Link: http://lkml.kernel.org/r/201907260928.23DE35406@keescook
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Joe Perches <joe@perches.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Cc: David Laight <David.Laight@aculab.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Stephen Kitt <steve@sk2.org>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/string.c