Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add KASAN_PANIC, an option to turn KASAN warning into ke...
details: https://anonhg.NetBSD.org/src/rev/e55534c0e427
branches: trunk
changeset: 457199:e55534c0e427
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Jun 15 06:40:34 2019 +0000
description:
Add KASAN_PANIC, an option to turn KASAN warning into kernel panics,
requested by Siddharth. While here clarify a little.
diffstat:
sys/arch/amd64/conf/GENERIC | 14 ++++++++------
sys/arch/evbarm/conf/GENERIC64 | 12 ++++++++----
sys/conf/files | 3 ++-
sys/kern/subr_asan.c | 12 +++++++++---
4 files changed, 27 insertions(+), 14 deletions(-)
diffs (119 lines):
diff -r 92774fd3a838 -r e55534c0e427 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC Sat Jun 15 04:00:17 2019 +0000
+++ b/sys/arch/amd64/conf/GENERIC Sat Jun 15 06:40:34 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.528 2019/05/24 14:28:48 nonaka Exp $
+# $NetBSD: GENERIC,v 1.529 2019/06/15 06:40:34 maxv Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.528 $"
+#ident "GENERIC-$Revision: 1.529 $"
maxusers 64 # estimated number of users
@@ -123,10 +123,12 @@
# Kernel Address Sanitizer (kASan). You need to disable SVS to use it.
# The quarantine is optional and can help KASAN find more use-after-frees.
-#makeoptions KASAN=1 # Kernel Address Sanitizer
-#options KASAN
-#no options SVS
-#options POOL_QUARANTINE
+# Use KASAN_PANIC if you want panics instead of warnings.
+#makeoptions KASAN=1 # mandatory
+#options KASAN # mandatory
+#no options SVS # mandatory
+#options POOL_QUARANTINE # optional
+#options KASAN_PANIC # optional
# Kernel Info Leak Detector.
#makeoptions KLEAK=1
diff -r 92774fd3a838 -r e55534c0e427 sys/arch/evbarm/conf/GENERIC64
--- a/sys/arch/evbarm/conf/GENERIC64 Sat Jun 15 04:00:17 2019 +0000
+++ b/sys/arch/evbarm/conf/GENERIC64 Sat Jun 15 06:40:34 2019 +0000
@@ -1,5 +1,5 @@
#
-# $NetBSD: GENERIC64,v 1.98 2019/06/13 13:35:41 jmcneill Exp $
+# $NetBSD: GENERIC64,v 1.99 2019/06/15 06:40:34 maxv Exp $
#
# GENERIC ARM (aarch64) kernel
#
@@ -132,9 +132,13 @@
#options EARLYCONS=thunderx, CONSADDR=0x87e024000000
#options EARLYCONS=virt
-# Kernel Address Sanitizer (kASan).
-#makeoptions KASAN=1 # Kernel Address Sanitizer
-#options KASAN
+# Kernel Address Sanitizer (kASan). The quarantine is optional and can
+# help KASAN find more use-after-frees. Use KASAN_PANIC if you want panics
+# instead of warnings.
+#makeoptions KASAN=1 # mandatory
+#options KASAN # mandatory
+#options POOL_QUARANTINE # optional
+#options KASAN_PANIC # optional
makeoptions DEBUG="-g" # compile full symbol table
makeoptions COPY_SYMTAB=1
diff -r 92774fd3a838 -r e55534c0e427 sys/conf/files
--- a/sys/conf/files Sat Jun 15 04:00:17 2019 +0000
+++ b/sys/conf/files Sat Jun 15 06:40:34 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1236 2019/05/17 03:34:26 ozaki-r Exp $
+# $NetBSD: files,v 1.1237 2019/06/15 06:40:34 maxv Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20171118
@@ -30,6 +30,7 @@
defflag opt_diagnostic.h _DIAGNOSTIC
defflag GPROF
defflag KASAN
+defflag opt_kasan.h KASAN_PANIC
defflag KLEAK
defflag KCOV
defflag opt_pool.h POOL_QUARANTINE
diff -r 92774fd3a838 -r e55534c0e427 sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c Sat Jun 15 04:00:17 2019 +0000
+++ b/sys/kern/subr_asan.c Sat Jun 15 06:40:34 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_asan.c,v 1.9 2019/05/04 17:19:10 maxv Exp $ */
+/* $NetBSD: subr_asan.c,v 1.10 2019/06/15 06:40:34 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.9 2019/05/04 17:19:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.10 2019/06/15 06:40:34 maxv Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -43,6 +43,12 @@
#include <uvm/uvm.h>
+#ifdef KASAN_PANIC
+#define REPORT panic
+#else
+#define REPORT printf
+#endif
+
/* ASAN constants. Part of the compiler ABI. */
#define KASAN_SHADOW_SCALE_SHIFT 3
#define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT)
@@ -185,7 +191,7 @@
kasan_report(unsigned long addr, size_t size, bool write, unsigned long pc,
uint8_t code)
{
- printf("ASan: Unauthorized Access In %p: Addr %p [%zu byte%s, %s,"
+ REPORT("ASan: Unauthorized Access In %p: Addr %p [%zu byte%s, %s,"
" %s]\n",
(void *)pc, (void *)addr, size, (size > 1 ? "s" : ""),
(write ? "write" : "read"), kasan_code_name(code));
Home |
Main Index |
Thread Index |
Old Index