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 kcopy and copystr.



details:   https://anonhg.NetBSD.org/src/rev/1375d53aa349
branches:  trunk
changeset: 451037:1375d53aa349
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat May 04 10:07:10 2019 +0000

description:
Add KASAN instrumentation for kcopy and copystr.

diffstat:

 sys/kern/subr_asan.c |  25 +++++++++++++++++++++++--
 sys/sys/systm.h      |  11 +++++++++--
 2 files changed, 32 insertions(+), 4 deletions(-)

diffs (99 lines):

diff -r fa797b9d23ea -r 1375d53aa349 sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c      Sat May 04 09:43:16 2019 +0000
+++ b/sys/kern/subr_asan.c      Sat May 04 10:07:10 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_asan.c,v 1.7 2019/04/11 17:43:45 maxv Exp $       */
+/*     $NetBSD: subr_asan.c,v 1.8 2019/05/04 10:07:10 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.7 2019/04/11 17:43:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.8 2019/05/04 10:07:10 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -479,18 +479,39 @@
        return (s - str);
 }
 
+#undef kcopy
+#undef copystr
 #undef copyinstr
 #undef copyoutstr
 #undef copyin
 
+int    kasan_kcopy(const void *, void *, size_t);
+int    kasan_copystr(const void *, void *, size_t, size_t *);
 int    kasan_copyinstr(const void *, void *, size_t, size_t *);
 int    kasan_copyoutstr(const void *, void *, size_t, size_t *);
 int    kasan_copyin(const void *, void *, size_t);
+int    kcopy(const void *, void *, size_t);
+int    copystr(const void *, void *, size_t, size_t *);
 int    copyinstr(const void *, void *, size_t, size_t *);
 int    copyoutstr(const void *, void *, size_t, size_t *);
 int    copyin(const void *, void *, size_t);
 
 int
+kasan_kcopy(const void *src, void *dst, size_t len)
+{
+       kasan_shadow_check((unsigned long)src, len, false, __RET_ADDR);
+       kasan_shadow_check((unsigned long)dst, len, true, __RET_ADDR);
+       return kcopy(src, dst, len);
+}
+
+int
+kasan_copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
+{
+       kasan_shadow_check((unsigned long)kdaddr, len, true, __RET_ADDR);
+       return copystr(kfaddr, kdaddr, len, done);
+}
+
+int
 kasan_copyin(const void *uaddr, void *kaddr, size_t len)
 {
        kasan_shadow_check((unsigned long)kaddr, len, true, __RET_ADDR);
diff -r fa797b9d23ea -r 1375d53aa349 sys/sys/systm.h
--- a/sys/sys/systm.h   Sat May 04 09:43:16 2019 +0000
+++ b/sys/sys/systm.h   Sat May 04 10:07:10 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: systm.h,v 1.283 2019/04/11 17:43:45 maxv Exp $ */
+/*     $NetBSD: systm.h,v 1.284 2019/05/04 10:07:11 maxv Exp $ */
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -260,7 +260,12 @@
 
 void   tablefull(const char *, const char *);
 
+#if defined(_KERNEL) && defined(KASAN)
+int    kasan_kcopy(const void *, void *, size_t);
+#define kcopy          kasan_kcopy
+#else
 int    kcopy(const void *, void *, size_t);
+#endif
 
 #ifdef _KERNEL
 #define bcopy(src, dst, len)   memcpy((dst), (src), (len))
@@ -268,15 +273,17 @@
 #define bcmp(a, b, len)                memcmp((a), (b), (len))
 #endif /* KERNEL */
 
-int    copystr(const void *, void *, size_t, size_t *);
 #if defined(_KERNEL) && defined(KASAN)
+int    kasan_copystr(const void *, void *, size_t, size_t *);
 int    kasan_copyinstr(const void *, void *, size_t, size_t *);
 int    kasan_copyoutstr(const void *, void *, size_t, size_t *);
 int    kasan_copyin(const void *, void *, size_t);
+#define copystr                kasan_copystr
 #define copyinstr      kasan_copyinstr
 #define copyoutstr     kasan_copyoutstr
 #define copyin         kasan_copyin
 #else
+int    copystr(const void *, void *, size_t, size_t *);
 int    copyinstr(const void *, void *, size_t, size_t *);
 int    copyoutstr(const void *, void *, size_t, size_t *);
 int    copyin(const void *, void *, size_t);



Home | Main Index | Thread Index | Old Index