diff options
author | Kees Cook <keescook@chromium.org> | 2022-09-29 02:24:53 -0700 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2022-11-01 10:04:51 -0700 |
commit | 9e4a617757273a86b560c1ece40c48e4940a3c79 (patch) | |
tree | 324f6fc68db62db7baeef3adc173ae50862ebf1e /include/linux/fortify-string.h | |
parent | 96fce387d58fa8eae6e8d9b1ecdfbc18292d7a68 (diff) |
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>
Diffstat (limited to 'include/linux/fortify-string.h')
-rw-r--r-- | include/linux/fortify-string.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h index e5b39b1cc2fc..49782f63f015 100644 --- a/include/linux/fortify-string.h +++ b/include/linux/fortify-string.h @@ -659,7 +659,8 @@ __FORTIFY_INLINE void *memchr_inv(const void * const POS0 p, int c, size_t size) return __real_memchr_inv(p, c, size); } -extern void *__real_kmemdup(const void *src, size_t len, gfp_t gfp) __RENAME(kmemdup); +extern void *__real_kmemdup(const void *src, size_t len, gfp_t gfp) __RENAME(kmemdup) + __realloc_size(2); __FORTIFY_INLINE void *kmemdup(const void * const POS0 p, size_t size, gfp_t gfp) { size_t p_size = __struct_size(p); |