include/linux/fortify-string.h:59:33: warning: '__builtin_memset' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807

From: kernel test robot
Date: Wed Oct 18 2023 - 06:59:40 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 06dc10eae55b5ceabfef287a7e5f16ceea204aa0
commit: 439a1bcac648fe9b59210cde8991fb2acf37bdab fortify: Use __builtin_dynamic_object_size() when available
date: 10 months ago
config: s390-randconfig-r002-20230326 (https://download.01.org/0day-ci/archive/20231018/202310181852.t3zhZN02-lkp@xxxxxxxxx/config)
compiler: s390-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231018/202310181852.t3zhZN02-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310181852.t3zhZN02-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

In file included from include/linux/string.h:253,
from include/linux/bitmap.h:11,
from include/linux/cpumask.h:12,
from include/linux/smp.h:13,
from include/linux/lockdep.h:14,
from include/linux/spinlock.h:63,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:7,
from include/linux/slab.h:15,
from drivers/misc/lkdtm/usercopy.c:7:
drivers/misc/lkdtm/usercopy.c: In function 'do_usercopy_slab_size':
>> include/linux/fortify-string.h:59:33: warning: '__builtin_memset' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
59 | #define __underlying_memset __builtin_memset
| ^
include/linux/fortify-string.h:453:9: note: in expansion of macro '__underlying_memset'
453 | __underlying_memset(p, c, __fortify_size); \
| ^~~~~~~~~~~~~~~~~~~
include/linux/fortify-string.h:461:25: note: in expansion of macro '__fortify_memset_chk'
461 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
| ^~~~~~~~~~~~~~~~~~~~
drivers/misc/lkdtm/usercopy.c:157:9: note: in expansion of macro 'memset'
157 | memset(one, 'A', size);
| ^~~~~~


vim +/__builtin_memset +59 include/linux/fortify-string.h

78a498c3a227f2 Alexander Potapenko 2022-10-24 46
78a498c3a227f2 Alexander Potapenko 2022-10-24 47 #if defined(__SANITIZE_MEMORY__)
78a498c3a227f2 Alexander Potapenko 2022-10-24 48 /*
78a498c3a227f2 Alexander Potapenko 2022-10-24 49 * For KMSAN builds all memcpy/memset/memmove calls should be replaced by the
78a498c3a227f2 Alexander Potapenko 2022-10-24 50 * corresponding __msan_XXX functions.
78a498c3a227f2 Alexander Potapenko 2022-10-24 51 */
78a498c3a227f2 Alexander Potapenko 2022-10-24 52 #include <linux/kmsan_string.h>
78a498c3a227f2 Alexander Potapenko 2022-10-24 53 #define __underlying_memcpy __msan_memcpy
78a498c3a227f2 Alexander Potapenko 2022-10-24 54 #define __underlying_memmove __msan_memmove
78a498c3a227f2 Alexander Potapenko 2022-10-24 55 #define __underlying_memset __msan_memset
78a498c3a227f2 Alexander Potapenko 2022-10-24 56 #else
a28a6e860c6cf2 Francis Laniel 2021-02-25 57 #define __underlying_memcpy __builtin_memcpy
a28a6e860c6cf2 Francis Laniel 2021-02-25 58 #define __underlying_memmove __builtin_memmove
a28a6e860c6cf2 Francis Laniel 2021-02-25 @59 #define __underlying_memset __builtin_memset
78a498c3a227f2 Alexander Potapenko 2022-10-24 60 #endif
78a498c3a227f2 Alexander Potapenko 2022-10-24 61

:::::: The code at line 59 was first introduced by commit
:::::: a28a6e860c6cf231cf3c5171c75c342adcd00406 string.h: move fortified functions definitions in a dedicated header.

:::::: TO: Francis Laniel <laniel_francis@xxxxxxxxxxxxxxxxxxx>
:::::: CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki