Skip to content

Commit 0e410e1

Browse files
xairytorvalds
authored andcommitted
kasan: don't emit builtin calls when sanitization is off
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 <[email protected]> Acked-by: Nick Desaulniers <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Michal Marek <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e237f98 commit 0e410e1

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ export MAKE LEX YACC AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
434434
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
435435

436436
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
437-
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN
437+
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
438+
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
438439
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
439440
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
440441
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL

scripts/Makefile.kasan

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ else
3131
endif
3232

3333
CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
34+
35+
CFLAGS_KASAN_NOSANITIZE := -fno-builtin
36+
3437
endif

scripts/Makefile.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ endif
121121
ifeq ($(CONFIG_KASAN),y)
122122
_c_flags += $(if $(patsubst n%,, \
123123
$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
124-
$(CFLAGS_KASAN))
124+
$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
125125
endif
126126

127127
ifeq ($(CONFIG_UBSAN),y)

0 commit comments

Comments
 (0)