string: Add __realloc_size hint to kmemdup()
authorKees Cook <keescook@chromium.org>
Thu, 29 Sep 2022 09:24:53 +0000 (02:24 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 1 Nov 2022 17:04:51 +0000 (10:04 -0700)
commit9e4a617757273a86b560c1ece40c48e4940a3c79
tree324f6fc68db62db7baeef3adc173ae50862ebf1e
parent96fce387d58fa8eae6e8d9b1ecdfbc18292d7a68
string: Add __realloc_size hint to kmemdup()

Add __realloc_size() hint to kmemdup() so the compiler can reason about
the length of the returned buffer. (These must not use __alloc_size,
since those include __malloc which says the contents aren't defined[1]).

[1] https://lore.kernel.org/linux-hardening/d199c2af-06af-8a50-a6a1-00eefa0b67b4@prevas.dk/

Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
include/linux/fortify-string.h
include/linux/string.h