Skip to content

Commit 0a827ce

Browse files
xairyZhengShunQian
authored andcommitted
kasan: don't emit builtin calls when sanitization is off
commit 0e410e1 upstream. 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]> [ Nick : Backported to 4.4 avoiding KUBSAN ] Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 22ceddd commit 0a827ce

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
442442
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
443443

444444
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
445-
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KCOV CFLAGS_KASAN
445+
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
446+
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
447+
export CFLAGS_KCOV
446448
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
447449
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
448450
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL

scripts/Makefile.kasan

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ else
2828
CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
2929
endif
3030
endif
31+
32+
CFLAGS_KASAN_NOSANITIZE := -fno-builtin
33+
3134
endif

scripts/Makefile.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ endif
126126
ifeq ($(CONFIG_KASAN),y)
127127
_c_flags += $(if $(patsubst n%,, \
128128
$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
129-
$(CFLAGS_KASAN))
129+
$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
130130
endif
131131

132132
ifeq ($(CONFIG_KCOV),y)

0 commit comments

Comments
 (0)