The patch titled Subject: string: use __builtin_memcpy() in strlcpy/strlcat has been added to the -mm mm-hotfixes-unstable branch. Its filename is string-use-__builtin_memcpy-in-strlcpy-strlcat.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/string-use-__builtin_memcpy-in-strlcpy-strlcat.patch This patch will later appear in the mm-hotfixes-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Alexander Potapenko <glider@xxxxxxxxxx> Subject: string: use __builtin_memcpy() in strlcpy/strlcat Date: Tue, 30 May 2023 10:39:11 +0200 lib/string.c is built with -ffreestanding, which prevents the compiler from replacing certain functions with calls to their library versions. On the other hand, this also prevents Clang and GCC from instrumenting calls to memcpy() when building with KASAN, KCSAN or KMSAN: - KASAN normally replaces memcpy() with __asan_memcpy() with the additional cc-param,asan-kernel-mem-intrinsic-prefix=1; - KCSAN and KMSAN replace memcpy() with __tsan_memcpy() and __msan_memcpy() by default. To let the tools catch memory accesses from strlcpy/strlcat, replace the calls to memcpy() with __builtin_memcpy(), which KASAN, KCSAN and KMSAN are able to replace even in -ffreestanding mode. This preserves the behavior in normal builds (__builtin_memcpy() ends up being replaced with memcpy()), and does not introduce new instrumentation in unwanted places, as strlcpy/strlcat are already instrumented. Link: https://lkml.kernel.org/r/20230530083911.1104336-1-glider@xxxxxxxxxx Link: https://lore.kernel.org/all/20230224085942.1791837-1-elver@xxxxxxxxxx/ Signed-off-by: Alexander Potapenko <glider@xxxxxxxxxx> Suggested-by: Marco Elver <elver@xxxxxxxxxx> Acked-by: Kees Cook <keescook@xxxxxxxxxxxx> Reviewed-by: Marco Elver <elver@xxxxxxxxxx> Cc: Andy Shevchenko <andy@xxxxxxxxxx> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Cc: Nathan Chancellor <nathan@xxxxxxxxxx> Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/lib/string.c~string-use-__builtin_memcpy-in-strlcpy-strlcat +++ a/lib/string.c @@ -110,7 +110,7 @@ size_t strlcpy(char *dest, const char *s if (size) { size_t len = (ret >= size) ? size - 1 : ret; - memcpy(dest, src, len); + __builtin_memcpy(dest, src, len); dest[len] = '\0'; } return ret; @@ -260,7 +260,7 @@ size_t strlcat(char *dest, const char *s count -= dsize; if (len >= count) len = count-1; - memcpy(dest, src, len); + __builtin_memcpy(dest, src, len); dest[len] = 0; return res; } _ Patches currently in -mm which might be from glider@xxxxxxxxxx are string-use-__builtin_memcpy-in-strlcpy-strlcat.patch