Source-Changes-HG archive

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

[src/trunk]: src/sys Add back the KASAN ifdefs in kern_malloc until we sort o...



details:   https://anonhg.NetBSD.org/src/rev/595f386b7a8d
branches:  trunk
changeset: 365580:595f386b7a8d
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Aug 22 12:42:06 2018 +0000

description:
Add back the KASAN ifdefs in kern_malloc until we sort out the type issue,
and fix sys/asan.h. Tested on i386, amd64 and amd64-kasan.

diffstat:

 sys/kern/kern_malloc.c |  12 ++++++++++--
 sys/sys/asan.h         |  15 ++++-----------
 2 files changed, 14 insertions(+), 13 deletions(-)

diffs (99 lines):

diff -r bffffb01a57b -r 595f386b7a8d sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c    Wed Aug 22 12:14:29 2018 +0000
+++ b/sys/kern/kern_malloc.c    Wed Aug 22 12:42:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_malloc.c,v 1.151 2018/08/22 09:38:21 maxv Exp $   */
+/*     $NetBSD: kern_malloc.c,v 1.152 2018/08/22 12:42:06 maxv Exp $   */
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.151 2018/08/22 09:38:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.152 2018/08/22 12:42:06 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kasan.h"
@@ -108,12 +108,16 @@
 kern_malloc(unsigned long size, int flags)
 {
        const int kmflags = (flags & M_NOWAIT) ? KM_NOSLEEP : KM_SLEEP;
+#ifdef KASAN
        const size_t origsize = size;
+#endif
        size_t allocsize, hdroffset;
        struct malloc_header *mh;
        void *p;
 
+#ifdef KASAN
        kasan_add_redzone(&size);
+#endif
 
        if (size >= PAGE_SIZE) {
                if (size > (ULONG_MAX-PAGE_SIZE))
@@ -140,7 +144,9 @@
 #endif
        mh++;
 
+#ifdef KASAN
        kasan_alloc(mh, origsize, size);
+#endif
 
        return mh;
 }
@@ -153,7 +159,9 @@
        mh = addr;
        mh--;
 
+#ifdef KASAN
        kasan_free(addr, mh->mh_size);
+#endif
 
        if (mh->mh_size >= PAGE_SIZE + sizeof(struct malloc_header))
                kmem_intr_free((char *)addr - PAGE_SIZE,
diff -r bffffb01a57b -r 595f386b7a8d sys/sys/asan.h
--- a/sys/sys/asan.h    Wed Aug 22 12:14:29 2018 +0000
+++ b/sys/sys/asan.h    Wed Aug 22 12:42:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asan.h,v 1.5 2018/08/22 12:14:29 kre Exp $     */
+/*     $NetBSD: asan.h,v 1.6 2018/08/22 12:42:06 maxv Exp $    */
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -39,31 +39,24 @@
 void kasan_alloc(const void *, size_t, size_t);
 void kasan_free(const void *, size_t);
 #else
-#if 0
-/* there are type issues - kmem_alloc() takes a u_long size not size_t */
-static void __inline __unused
+__inline static void __unused
 kasan_add_redzone(size_t *size __unused)
 {
        /* nothing */
 }
 
-static void __inline __unused
+__inline static void __unused
 kasan_alloc(const void *addr __unused, size_t size __unused,
     size_t sz_with_redz __unused)
 {
        /* nothing */
 }
 
-static void __inline __unused
+__inline static void __unused
 kasan_free(const void *addr __unused, size_t sz_with_redz __unused)
 {
        /* nothing */
 }
-#else
-#define        kasan_add_redzone(SP)   __nothing
-#define        kasan_alloc(P, S1, S2)  __nothing
-#define        kasan_free(P, S)        __nothing
-#endif
 #endif
 
 #endif /* !_SYS_ASAN_H_ */



Home | Main Index | Thread Index | Old Index