Skip to content

Commit 26fb3a4

Browse files
Ada Couprie Diazgregkh
authored andcommitted
kasan: fix GCC mem-intrinsic prefix with sw tags
commit 51337a9 upstream. GCC doesn't support "hwasan-kernel-mem-intrinsic-prefix", only "asan-kernel-mem-intrinsic-prefix"[0], while LLVM supports both. This is already taken into account when checking "CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX", but not in the KASAN Makefile adding those parameters when "CONFIG_KASAN_SW_TAGS" is enabled. Replace the version check with "CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX", which already validates that mem-intrinsic prefix parameter can be used, and choose the correct name depending on compiler. GCC 13 and above trigger "CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX" which prevents `mem{cpy,move,set}()` being redefined in "mm/kasan/shadow.c" since commit 36be5cb ("kasan: treat meminstrinsic as builtins in uninstrumented files"), as we expect the compiler to prefix those calls with `__(hw)asan_` instead. But as the option passed to GCC has been incorrect, the compiler has not been emitting those prefixes, effectively never calling the instrumented versions of `mem{cpy,move,set}()` with "CONFIG_KASAN_SW_TAGS" enabled. If "CONFIG_FORTIFY_SOURCES" is enabled, this issue would be mitigated as it redefines `mem{cpy,move,set}()` and properly aliases the `__underlying_mem*()` that will be called to the instrumented versions. Link: https://lkml.kernel.org/r/20250821120735.156244-1-ada.coupriediaz@arm.com Link: https://gcc.gnu.org/onlinedocs/gcc-13.4.0/gcc/Optimize-Options.html [0] Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com> Fixes: 36be5cb ("kasan: treat meminstrinsic as builtins in uninstrumented files") Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <andreyknvl@gmail.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Marco Elver <elver@google.com> Cc: Marc Rutland <mark.rutland@arm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b921c28 commit 26fb3a4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/Makefile.kasan

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ kasan_params += hwasan-instrument-stack=$(stack_enable) \
8686
hwasan-use-short-granules=0 \
8787
hwasan-inline-all-checks=0
8888

89-
# Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*().
90-
ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y)
91-
kasan_params += hwasan-kernel-mem-intrinsic-prefix=1
92-
endif
89+
# Instrument memcpy/memset/memmove calls by using instrumented __(hw)asan_mem*().
90+
ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
91+
ifdef CONFIG_CC_IS_GCC
92+
kasan_params += asan-kernel-mem-intrinsic-prefix=1
93+
else
94+
kasan_params += hwasan-kernel-mem-intrinsic-prefix=1
95+
endif
96+
endif # CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
9397

9498
endif # CONFIG_KASAN_SW_TAGS
9599

0 commit comments

Comments
 (0)