Skip to content

Commit e186d8b

Browse files
xairygregkh
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 <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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d16919a commit e186d8b

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎Makefile‎

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

418418
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
419-
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN
419+
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
420+
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
420421
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
421422
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
422423
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
@@ -128,7 +128,7 @@ endif
128128
ifeq ($(CONFIG_KASAN),y)
129129
_c_flags += $(if $(patsubst n%,, \
130130
$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
131-
$(CFLAGS_KASAN))
131+
$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
132132
endif
133133

134134
ifeq ($(CONFIG_UBSAN),y)

0 commit comments

Comments
 (0)