From 01028c736cbcdba079967c787bee1551fc8439aa Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 13 Apr 2021 16:29:47 -0400 Subject: [PATCH] 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 --- sys/conf/kern.pre.mk | 10 ++++++++++ sys/conf/options | 1 + 2 files changed, 11 insertions(+) diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk index bb27969d6ec..539605f60ca 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 b6956193d84..882460fbf35 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