Module Name: src
Committed By: maxv
Date: Wed Aug 22 12:42:06 UTC 2018
Modified Files:
src/sys/kern: kern_malloc.c
src/sys/sys: asan.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/sys/kern/kern_malloc.c
cvs rdiff -u -r1.5 -r1.6 src/sys/sys/asan.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/kern_malloc.c
diff -u src/sys/kern/kern_malloc.c:1.151 src/sys/kern/kern_malloc.c:1.152
--- src/sys/kern/kern_malloc.c:1.151 Wed Aug 22 09:38:21 2018
+++ src/sys/kern/kern_malloc.c Wed Aug 22 12:42:06 2018
@@ -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 @@ void *
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 @@ kern_malloc(unsigned long size, int flag
#endif
mh++;
+#ifdef KASAN
kasan_alloc(mh, origsize, size);
+#endif
return mh;
}
@@ -153,7 +159,9 @@ kern_free(void *addr)
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,
Index: src/sys/sys/asan.h
diff -u src/sys/sys/asan.h:1.5 src/sys/sys/asan.h:1.6
--- src/sys/sys/asan.h:1.5 Wed Aug 22 12:14:29 2018
+++ src/sys/sys/asan.h Wed Aug 22 12:42:06 2018
@@ -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_add_redzone(size_t *);
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_ */