path: root/arch/x86/include/asm/string_64.h
diff options
authorAndrey Ryabinin <>2015-02-13 14:39:56 -0800
committerLinus Torvalds <>2015-02-13 21:21:41 -0800
commit393f203f5fd54421fddb1e2a263f64d3876eeadb (patch)
treee78e96b38ecd36eec62325cc2cc21e8d79397bc1 /arch/x86/include/asm/string_64.h
parent3f15801cdc2379ca4bf507f48bffd788f9e508ae (diff)
x86_64: kasan: add interceptors for memset/memmove/memcpy functions
Recently instrumentation of builtin functions calls was removed from GCC 5.0. To check the memory accessed by such functions, userspace asan always uses interceptors for them. So now we should do this as well. This patch declares memset/memmove/memcpy as weak symbols. In mm/kasan/kasan.c we have our own implementation of those functions which checks memory before accessing it. Default memset/memmove/memcpy now now always have aliases with '__' prefix. For files that built without kasan instrumentation (e.g. mm/slub.c) original mem* replaced (via #define) with prefixed variants, cause we don't want to check memory accesses there. Signed-off-by: Andrey Ryabinin <> Cc: Dmitry Vyukov <> Cc: Konstantin Serebryany <> Cc: Dmitry Chernenkov <> Signed-off-by: Andrey Konovalov <> Cc: Yuri Gribov <> Cc: Konstantin Khlebnikov <> Cc: Sasha Levin <> Cc: Christoph Lameter <> Cc: Joonsoo Kim <> Cc: Dave Hansen <> Cc: Andi Kleen <> Cc: Ingo Molnar <> Cc: Thomas Gleixner <> Cc: "H. Peter Anvin" <> Cc: Christoph Lameter <> Cc: Pekka Enberg <> Cc: David Rientjes <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'arch/x86/include/asm/string_64.h')
1 files changed, 17 insertions, 1 deletions
diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h
index 19e2c468fc2c..e4661196994e 100644
--- a/arch/x86/include/asm/string_64.h
+++ b/arch/x86/include/asm/string_64.h
@@ -27,11 +27,12 @@ static __always_inline void *__inline_memcpy(void *to, const void *from, size_t
function. */
#define __HAVE_ARCH_MEMCPY 1
+extern void *__memcpy(void *to, const void *from, size_t len);
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
extern void *memcpy(void *to, const void *from, size_t len);
-extern void *__memcpy(void *to, const void *from, size_t len);
#define memcpy(dst, src, len) \
({ \
size_t __len = (len); \
@@ -53,9 +54,11 @@ extern void *__memcpy(void *to, const void *from, size_t len);
void *memset(void *s, int c, size_t n);
+void *__memset(void *s, int c, size_t n);
void *memmove(void *dest, const void *src, size_t count);
+void *__memmove(void *dest, const void *src, size_t count);
int memcmp(const void *cs, const void *ct, size_t count);
size_t strlen(const char *s);
@@ -63,6 +66,19 @@ char *strcpy(char *dest, const char *src);
char *strcat(char *dest, const char *src);
int strcmp(const char *cs, const char *ct);
+#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
+ * For files that not instrumented (e.g. mm/slub.c) we
+ * should use not instrumented version of mem* functions.
+ */
+#undef memcpy
+#define memcpy(dst, src, len) __memcpy(dst, src, len)
+#define memmove(dst, src, len) __memmove(dst, src, len)
+#define memset(s, c, n) __memset(s, c, n)
#endif /* __KERNEL__ */
#endif /* _ASM_X86_STRING_64_H */