![Andrey Konovalov](/assets/img/avatar_default.png)
With KASAN enabled the kernel has two different memset() functions, one with KASAN checks (memset) and one without (__memset). KASAN uses some macro tricks to use the proper version where required. For example memset() calls in mm/slub.c are without KASAN checks, since they operate on poisoned slab object metadata. The issue is that clang emits memset() calls even when there is no memset() in the source code. They get linked with improper memset() implementation and the kernel fails to boot due to a huge amount of KASAN reports during early boot stages. The solution is to add -fno-builtin flag for files with KASAN_SANITIZE := n marker. Link: http://lkml.kernel.org/r/8ffecfffe04088c52c42b92739c2bd8a0bcb3f5e.1516384594.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Acked-by: Nick Desaulniers <ndesaulniers@google.com> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Michal Marek <michal.lkml@markovi.net> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Alexander Potapenko <glider@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
38 lines
1.1 KiB
Makefile
38 lines
1.1 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
ifdef CONFIG_KASAN
|
|
ifdef CONFIG_KASAN_INLINE
|
|
call_threshold := 10000
|
|
else
|
|
call_threshold := 0
|
|
endif
|
|
|
|
KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
|
|
|
|
CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
|
|
|
|
CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \
|
|
-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),)
|
|
ifneq ($(CONFIG_COMPILE_TEST),y)
|
|
$(warning Cannot use CONFIG_KASAN: \
|
|
-fsanitize=kernel-address is not supported by compiler)
|
|
endif
|
|
else
|
|
ifeq ($(CFLAGS_KASAN),)
|
|
ifneq ($(CONFIG_COMPILE_TEST),y)
|
|
$(warning CONFIG_KASAN: compiler does not support all options.\
|
|
Trying minimal configuration)
|
|
endif
|
|
CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
|
|
endif
|
|
endif
|
|
|
|
CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
|
|
|
|
CFLAGS_KASAN_NOSANITIZE := -fno-builtin
|
|
|
|
endif
|