Commit 1a69e7ce authored by Andrey Ryabinin's avatar Andrey Ryabinin Committed by Linus Torvalds
Browse files

kasan/Makefile: support LLVM style asan parameters

LLVM doesn't understand GCC-style paramters ("--param asan-foo=bar"), thus
we currently we don't use inline/globals/stack instrumentation when
building the kernel with clang.

Add support for LLVM-style parameters ("-mllvm -asan-foo=bar") to enable
all KASAN features.


Signed-off-by: default avatarAndrey Ryabinin <>
Signed-off-by: default avatarPaul Lawrence <>
Reviewed-by: default avatarAlexander Potapenko <>
Cc: Dmitry Vyukov <>
Cc: Greg Hackmann <>
Cc: Masahiro Yamada <>
Cc: Matthias Kaehlcke <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 53a98ed7
CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \ cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
-fasan-shadow-offset=$(KASAN_SHADOW_OFFSET) \
--param asan-stack=1 --param asan-globals=1 \
--param asan-instrumentation-with-call-threshold=$(call_threshold))
ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),)
...@@ -21,13 +18,23 @@ ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) ...@@ -21,13 +18,23 @@ ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),)
-fsanitize=kernel-address is not supported by compiler) -fsanitize=kernel-address is not supported by compiler)
endif endif
else else
ifeq ($(CFLAGS_KASAN),) # -fasan-shadow-offset fails without -fsanitize
ifneq ($(CONFIG_COMPILE_TEST),y) CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
$(warning CONFIG_KASAN: compiler does not support all options.\ -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
Trying minimal configuration) $(call cc-option, -fsanitize=kernel-address \
endif -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
# Now add all the compiler specific options that are valid standalone
$(call cc-param,asan-globals=1) \
$(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
$(call cc-param,asan-stack=1) \
$(call cc-param,asan-use-after-scope=1)
endif endif
endif endif
CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment