Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kasan: fix hwasan build for gcc

gcc-11 adds support for -fsanitize=kernel-hwaddress, so it becomes
possible to enable CONFIG_KASAN_SW_TAGS.

Unfortunately this fails to build at the moment, because the
corresponding command line arguments use llvm specific syntax.

Change it to use the cc-param macro instead, which works on both clang
and gcc.

[elver@google.com: fixup for "kasan: fix hwasan build for gcc"]
Link: https://lkml.kernel.org/r/YHQZVfVVLE/LDK2v@elver.google.com

Link: https://lkml.kernel.org/r/20210323124112.1229772-1-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Marco Elver <elver@google.com>
Reviewed-by: Marco Elver <elver@google.com>
Acked-by: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michal Marek <michal.lkml@markovi.net>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.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>

authored by

Arnd Bergmann and committed by
Linus Torvalds
5c595ac4 845be1cd

+6 -6
+6 -6
scripts/Makefile.kasan
··· 2 2 CFLAGS_KASAN_NOSANITIZE := -fno-builtin 3 3 KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) 4 4 5 + cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) 6 + 5 7 ifdef CONFIG_KASAN_GENERIC 6 8 7 9 ifdef CONFIG_KASAN_INLINE ··· 13 11 endif 14 12 15 13 CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address 16 - 17 - cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) 18 14 19 15 # -fasan-shadow-offset fails without -fsanitize 20 16 CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ ··· 36 36 ifdef CONFIG_KASAN_SW_TAGS 37 37 38 38 ifdef CONFIG_KASAN_INLINE 39 - instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET) 39 + instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)) 40 40 else 41 - instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1 41 + instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1) 42 42 endif 43 43 44 44 CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ 45 - -mllvm -hwasan-instrument-stack=$(CONFIG_KASAN_STACK) \ 46 - -mllvm -hwasan-use-short-granules=0 \ 45 + $(call cc-param,hwasan-instrument-stack=$(CONFIG_KASAN_STACK)) \ 46 + $(call cc-param,hwasan-use-short-granules=0) \ 47 47 $(instrumentation_flags) 48 48 49 49 endif # CONFIG_KASAN_SW_TAGS