Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Simplify the KASAN API, use only kasan_mark() and explai...
details: https://anonhg.NetBSD.org/src/rev/4c205727f108
branches: trunk
changeset: 446862:4c205727f108
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Dec 23 12:15:01 2018 +0000
description:
Simplify the KASAN API, use only kasan_mark() and explain briefly. The
alloc/free naming was too confusing.
diffstat:
sys/kern/kern_malloc.c | 8 ++++----
sys/kern/subr_asan.c | 23 +++++++++++++----------
sys/kern/subr_kmem.c | 8 ++++----
sys/kern/subr_pool.c | 14 +++++++-------
sys/sys/asan.h | 8 +++-----
sys/uvm/uvm_glue.c | 8 ++++----
6 files changed, 35 insertions(+), 34 deletions(-)
diffs (252 lines):
diff -r 3f2152b967c7 -r 4c205727f108 sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c Sun Dec 23 12:11:40 2018 +0000
+++ b/sys/kern/kern_malloc.c Sun Dec 23 12:15:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_malloc.c,v 1.154 2018/10/20 14:09:47 martin Exp $ */
+/* $NetBSD: kern_malloc.c,v 1.155 2018/12/23 12:15:01 maxv Exp $ */
/*
* Copyright (c) 1987, 1991, 1993
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.154 2018/10/20 14:09:47 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.155 2018/12/23 12:15:01 maxv Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
@@ -139,7 +139,7 @@
#endif
mh++;
- kasan_alloc(mh, origsize, size);
+ kasan_mark(mh, origsize, size);
return mh;
}
@@ -152,7 +152,7 @@
mh = addr;
mh--;
- kasan_free(addr, mh->mh_size);
+ kasan_mark(addr, mh->mh_size, mh->mh_size);
if (mh->mh_size >= PAGE_SIZE + sizeof(struct malloc_header))
kmem_intr_free((char *)addr - PAGE_SIZE,
diff -r 3f2152b967c7 -r 4c205727f108 sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c Sun Dec 23 12:11:40 2018 +0000
+++ b/sys/kern/subr_asan.c Sun Dec 23 12:15:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_asan.c,v 1.1 2018/10/31 06:26:26 maxv Exp $ */
+/* $NetBSD: subr_asan.c,v 1.2 2018/12/23 12:15:01 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.1 2018/10/31 06:26:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.2 2018/12/23 12:15:01 maxv Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -232,19 +232,22 @@
kasan_shadow_Nbyte_fill(stk, USPACE, 0);
}
+/*
+ * In an area of size 'sz_with_redz', mark the 'size' first bytes as valid,
+ * and the rest as invalid. There are generally two use cases:
+ *
+ * o kasan_mark(addr, origsize, size), with origsize < size. This marks the
+ * redzone at the end of the buffer as invalid.
+ *
+ * o kasan_mark(addr, size, size). This marks the entire buffer as valid.
+ */
void
-kasan_alloc(const void *addr, size_t size, size_t sz_with_redz)
+kasan_mark(const void *addr, size_t size, size_t sz_with_redz)
{
kasan_markmem(addr, sz_with_redz, false);
kasan_markmem(addr, size, true);
}
-void
-kasan_free(const void *addr, size_t sz_with_redz)
-{
- kasan_markmem(addr, sz_with_redz, true);
-}
-
/* -------------------------------------------------------------------------- */
#define ADDR_CROSSES_SCALE_BOUNDARY(addr, size) \
@@ -446,7 +449,7 @@
size_t i;
for (i = 0; i < n; i++) {
- kasan_alloc(globals[i].beg, globals[i].size,
+ kasan_mark(globals[i].beg, globals[i].size,
globals[i].size_with_redzone);
}
}
diff -r 3f2152b967c7 -r 4c205727f108 sys/kern/subr_kmem.c
--- a/sys/kern/subr_kmem.c Sun Dec 23 12:11:40 2018 +0000
+++ b/sys/kern/subr_kmem.c Sun Dec 23 12:15:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_kmem.c,v 1.71 2018/08/22 14:12:30 christos Exp $ */
+/* $NetBSD: subr_kmem.c,v 1.72 2018/12/23 12:15:01 maxv Exp $ */
/*-
* Copyright (c) 2009-2015 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.71 2018/08/22 14:12:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.72 2018/12/23 12:15:01 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_kmem.h"
@@ -271,7 +271,7 @@
FREECHECK_OUT(&kmem_freecheck, p);
kmem_size_set(p, requested_size);
p += SIZE_SIZE;
- kasan_alloc(p, origsize, size);
+ kasan_mark(p, origsize, size);
return p;
}
return p;
@@ -331,7 +331,7 @@
return;
}
- kasan_free(p, size);
+ kasan_mark(p, size, size);
p = (uint8_t *)p - SIZE_SIZE;
kmem_size_check(p, requested_size);
diff -r 3f2152b967c7 -r 4c205727f108 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c Sun Dec 23 12:11:40 2018 +0000
+++ b/sys/kern/subr_pool.c Sun Dec 23 12:15:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pool.c,v 1.230 2018/12/23 11:42:13 maxv Exp $ */
+/* $NetBSD: subr_pool.c,v 1.231 2018/12/23 12:15:01 maxv Exp $ */
/*
* Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.230 2018/12/23 11:42:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.231 2018/12/23 12:15:01 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -999,7 +999,7 @@
* Mark the pool_item as valid. The rest is already
* invalid.
*/
- kasan_alloc(pi, sizeof(*pi), sizeof(*pi));
+ kasan_mark(pi, sizeof(*pi), sizeof(*pi));
}
LIST_INSERT_HEAD(&ph->ph_itemlist, pi, pi_list);
@@ -2024,7 +2024,7 @@
* valid for the destructor. pool_put below will re-mark it
* as invalid.
*/
- kasan_alloc(object, pc->pc_pool.pr_reqsize,
+ kasan_mark(object, pc->pc_pool.pr_reqsize,
pc->pc_pool.pr_reqsize_with_redzone);
}
@@ -2719,7 +2719,7 @@
struct pool_allocator *pa = pp->pr_alloc;
if (pp->pr_redzone) {
- kasan_alloc(v, pa->pa_pagesz, pa->pa_pagesz);
+ kasan_mark(v, pa->pa_pagesz, pa->pa_pagesz);
}
(*pa->pa_free)(pp, v);
}
@@ -2858,7 +2858,7 @@
if (!pp->pr_redzone)
return;
#ifdef KASAN
- kasan_alloc(p, pp->pr_reqsize, pp->pr_reqsize_with_redzone);
+ kasan_mark(p, pp->pr_reqsize, pp->pr_reqsize_with_redzone);
#else
uint8_t *cp, pat;
const uint8_t *ep;
@@ -2887,7 +2887,7 @@
if (!pp->pr_redzone)
return;
#ifdef KASAN
- kasan_alloc(p, 0, pp->pr_reqsize_with_redzone);
+ kasan_mark(p, 0, pp->pr_reqsize_with_redzone);
#else
uint8_t *cp, pat, expected;
const uint8_t *ep;
diff -r 3f2152b967c7 -r 4c205727f108 sys/sys/asan.h
--- a/sys/sys/asan.h Sun Dec 23 12:11:40 2018 +0000
+++ b/sys/sys/asan.h Sun Dec 23 12:15:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: asan.h,v 1.8 2018/10/31 06:26:26 maxv Exp $ */
+/* $NetBSD: asan.h,v 1.9 2018/12/23 12:15:01 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -45,12 +45,10 @@
void kasan_softint(struct lwp *);
void kasan_add_redzone(size_t *);
-void kasan_alloc(const void *, size_t, size_t);
-void kasan_free(const void *, size_t);
+void kasan_mark(const void *, size_t, size_t);
#else
#define kasan_add_redzone(s) __nothing
-#define kasan_alloc(p, s, l) __nothing
-#define kasan_free(p, s) __nothing
+#define kasan_mark(p, s, l) __nothing
#endif
#endif /* !_SYS_ASAN_H_ */
diff -r 3f2152b967c7 -r 4c205727f108 sys/uvm/uvm_glue.c
--- a/sys/uvm/uvm_glue.c Sun Dec 23 12:11:40 2018 +0000
+++ b/sys/uvm/uvm_glue.c Sun Dec 23 12:15:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_glue.c,v 1.165 2018/11/04 13:48:27 mlelstv Exp $ */
+/* $NetBSD: uvm_glue.c,v 1.166 2018/12/23 12:15:01 maxv Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.165 2018/11/04 13:48:27 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.166 2018/12/23 12:15:01 maxv Exp $");
#include "opt_kgdb.h"
#include "opt_kstack.h"
@@ -384,7 +384,7 @@
uvm_uarea_free(vaddr_t uaddr)
{
- kasan_free((void *)uaddr, USPACE);
+ kasan_mark((void *)uaddr, USPACE, USPACE);
pool_cache_put(uvm_uarea_cache, (void *)uaddr);
}
@@ -392,7 +392,7 @@
uvm_uarea_system_free(vaddr_t uaddr)
{
- kasan_free((void *)uaddr, USPACE);
+ kasan_mark((void *)uaddr, USPACE, USPACE);
pool_cache_put(uvm_uarea_system_cache, (void *)uaddr);
}
Home |
Main Index |
Thread Index |
Old Index