aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2021-04-13 20:29:47 +0000
committerMark Johnston <markj@FreeBSD.org>2021-04-13 21:42:20 +0000
commit01028c736cbcdba079967c787bee1551fc8439aa (patch)
treeb6af2b0342f052c071b331b7843dc0ca579fef6b
parent86887853c39b0803009579e2b927bd67d524af63 (diff)
downloadsrc-01028c736cbcdba079967c787bee1551fc8439aa.tar.gz
src-01028c736cbcdba079967c787bee1551fc8439aa.zip
Add a KASAN option to the kernel build
LLVM support for enabling KASAN has not yet landed so the option is not yet usable, but hopefully this will change soon. Reviewed by: imp, andrew MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29454
-rw-r--r--sys/conf/kern.pre.mk10
-rw-r--r--sys/conf/options1
2 files changed, 11 insertions, 0 deletions
diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk
index bb27969d6eca..539605f60ca0 100644
--- a/sys/conf/kern.pre.mk
+++ b/sys/conf/kern.pre.mk
@@ -92,6 +92,16 @@ CFLAGS+= -fno-common
# XXX LOCORE means "don't declare C stuff" not "for locore.s".
ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} ${ASM_CFLAGS.${.IMPSRC:T}}
+KASAN_ENABLED!= grep KASAN opt_global.h || true ; echo
+.if !empty(KASAN_ENABLED)
+SAN_CFLAGS+= -fsanitize=kernel-address \
+ -mllvm -asan-stack=true \
+ -mllvm -asan-instrument-dynamic-allocas=true \
+ -mllvm -asan-globals=true \
+ -mllvm -asan-use-after-scope=true \
+ -mllvm -asan-instrumentation-with-call-threshold=0
+.endif
+
KCSAN_ENABLED!= grep KCSAN opt_global.h || true ; echo
.if !empty(KCSAN_ENABLED)
SAN_CFLAGS+= -fsanitize=thread
diff --git a/sys/conf/options b/sys/conf/options
index b6956193d841..882460fbf35b 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -229,6 +229,7 @@ ZSTDIO opt_zstdio.h
# Sanitizers
COVERAGE opt_global.h
+KASAN opt_global.h
KCOV
KCSAN opt_global.h
KUBSAN opt_global.h