From 1f8d4ff48b7e780d6baccd14cc326874602a187f Mon Sep 17 00:00:00 2001 From: maxv Date: Sat, 7 Sep 2019 09:46:07 +0000 Subject: [PATCH] Add KASAN instrumentation for memmove. --- sys/kern/subr_asan.c | 12 ++++++++++-- sys/lib/libkern/libkern.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sys/kern/subr_asan.c b/sys/kern/subr_asan.c index c666261ad539..10a61c8c4d19 100644 --- a/sys/kern/subr_asan.c +++ b/sys/kern/subr_asan.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_asan.c,v 1.11 2019/09/05 16:19:16 maxv Exp $ */ +/* $NetBSD: subr_asan.c,v 1.12 2019/09/07 09:46:07 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.11 2019/09/05 16:19:16 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.12 2019/09/07 09:46:07 maxv Exp $"); #include #include @@ -447,6 +447,14 @@ kasan_memset(void *b, int c, size_t len) return __builtin_memset(b, c, len); } +void * +kasan_memmove(void *dst, const void *src, size_t len) +{ + kasan_shadow_check((unsigned long)src, len, false, __RET_ADDR); + kasan_shadow_check((unsigned long)dst, len, true, __RET_ADDR); + return __builtin_memmove(dst, src, len); +} + char * kasan_strcpy(char *dst, const char *src) { diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index cbbec539b138..04620f1c983f 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -1,4 +1,4 @@ -/* $NetBSD: libkern.h,v 1.130 2018/09/03 16:29:35 riastradh Exp $ */ +/* $NetBSD: libkern.h,v 1.131 2019/09/07 09:46:07 maxv Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -370,9 +370,9 @@ void *memset(void *, int, size_t); void *memmem(const void *, size_t, const void *, size_t); #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) #if defined(_KERNEL) && defined(KASAN) -void *kasan_memset(void *, int, size_t); -int kasan_memcmp(const void *, const void *, size_t); void *kasan_memcpy(void *, const void *, size_t); +int kasan_memcmp(const void *, const void *, size_t); +void *kasan_memset(void *, int, size_t); #define memcpy(d, s, l) kasan_memcpy(d, s, l) #define memcmp(a, b, l) kasan_memcmp(a, b, l) #define memset(d, v, l) kasan_memset(d, v, l) @@ -437,7 +437,13 @@ int inet_aton(const char *, struct in_addr *); char *intoa(u_int32_t); #define inet_ntoa(a) intoa((a).s_addr) void *memchr(const void *, int, size_t); + void *memmove(void *, const void *, size_t); +#if defined(_KERNEL) && defined(KASAN) +void *kasan_memmove(void *, const void *, size_t); +#define memmove(d, s, l) kasan_memmove(d, s, l) +#endif + int pmatch(const char *, const char *, const char **); #ifndef SMALL_RANDOM void srandom(unsigned long);