mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-06 01:26:56 +01:00
Where the compiler instruments meminstrinsics by generating calls to
__asan/__hwasan_ prefixed functions, let the compiler consider
memintrinsics as builtin again.
To do so, never override memset/memmove/memcpy if the compiler does the
correct instrumentation - even on !GENERIC_ENTRY architectures.
[[email protected]: powerpc: don't rename memintrinsics if compiler adds prefixes]
Link: https://lore.kernel.org/all/[email protected]/ [1]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Fixes: 69d4c0d321 ("entry, kasan, x86: Disallow overriding mem*() functions")
Signed-off-by: Marco Elver <[email protected]>
Reviewed-by: Andrey Konovalov <[email protected]>
Tested-by: Linux Kernel Functional Testing <[email protected]>
Tested-by: Naresh Kamboju <[email protected]>
Acked-by: Michael Ellerman <[email protected]> (powerpc)
Cc: Alexander Potapenko <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Borislav Petkov (AMD) <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jakub Jelinek <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: Peter Zijlstra (Intel) <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vincenzo Frascino <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
77 lines
2.4 KiB
Makefile
77 lines
2.4 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
|
|
# Safe for compiler to generate meminstrinsic calls in uninstrumented files.
|
|
CFLAGS_KASAN_NOSANITIZE :=
|
|
else
|
|
# Don't let compiler generate memintrinsic calls in uninstrumented files
|
|
# because they are instrumented.
|
|
CFLAGS_KASAN_NOSANITIZE := -fno-builtin
|
|
endif
|
|
|
|
KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
|
|
|
|
cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
|
|
|
|
ifdef CONFIG_KASAN_STACK
|
|
stack_enable := 1
|
|
else
|
|
stack_enable := 0
|
|
endif
|
|
|
|
ifdef CONFIG_KASAN_GENERIC
|
|
|
|
ifdef CONFIG_KASAN_INLINE
|
|
call_threshold := 10000
|
|
else
|
|
call_threshold := 0
|
|
endif
|
|
|
|
CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
|
|
|
|
# -fasan-shadow-offset fails without -fsanitize
|
|
CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
|
|
-fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
|
|
$(call cc-option, -fsanitize=kernel-address \
|
|
-mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
|
|
|
|
ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
|
|
CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
|
|
else
|
|
# Now add all the compiler specific options that are valid standalone
|
|
CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
|
|
$(call cc-param,asan-globals=1) \
|
|
$(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
|
|
$(call cc-param,asan-instrument-allocas=1)
|
|
endif
|
|
|
|
CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
|
|
|
|
# Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*()
|
|
# instead. With compilers that don't support this option, compiler-inserted
|
|
# memintrinsics won't be checked by KASAN on GENERIC_ENTRY architectures.
|
|
CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1)
|
|
|
|
endif # CONFIG_KASAN_GENERIC
|
|
|
|
ifdef CONFIG_KASAN_SW_TAGS
|
|
|
|
ifdef CONFIG_KASAN_INLINE
|
|
instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET))
|
|
else
|
|
instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1)
|
|
endif
|
|
|
|
CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
|
|
$(call cc-param,hwasan-instrument-stack=$(stack_enable)) \
|
|
$(call cc-param,hwasan-use-short-granules=0) \
|
|
$(call cc-param,hwasan-inline-all-checks=0) \
|
|
$(instrumentation_flags)
|
|
|
|
# Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*().
|
|
CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1)
|
|
|
|
endif # CONFIG_KASAN_SW_TAGS
|
|
|
|
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
|