Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add KASAN instrumentation for memmove.



details:   https://anonhg.NetBSD.org/src/rev/e73e75e3273c
branches:  trunk
changeset: 965218:e73e75e3273c
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Sep 07 09:46:07 2019 +0000

description:
Add KASAN instrumentation for memmove.

diffstat:

 sys/kern/subr_asan.c      |  12 ++++++++++--
 sys/lib/libkern/libkern.h |  12 +++++++++---
 2 files changed, 19 insertions(+), 5 deletions(-)

diffs (68 lines):

diff -r 82ab96fd78ed -r e73e75e3273c sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c      Sat Sep 07 09:27:25 2019 +0000
+++ b/sys/kern/subr_asan.c      Sat Sep 07 09:46:07 2019 +0000
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
 #include <sys/device.h>
@@ -447,6 +447,14 @@
        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 -r 82ab96fd78ed -r e73e75e3273c sys/lib/libkern/libkern.h
--- a/sys/lib/libkern/libkern.h Sat Sep 07 09:27:25 2019 +0000
+++ b/sys/lib/libkern/libkern.h Sat Sep 07 09:46:07 2019 +0000
@@ -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   *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);
+void   *kasan_memcpy(void *, const void *, size_t);
 int     kasan_memcmp(const void *, const void *, size_t);
-void   *kasan_memcpy(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 @@
 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);



Home | Main Index | Thread Index | Old Index