Skip to content

Commit 9a48e75

Browse files
committed
compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer
When Clang is using the hwaddress sanitizer, it sets __SANITIZE_ADDRESS__ explicitly: #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) /* Emulate GCC's __SANITIZE_ADDRESS__ flag */ #define __SANITIZE_ADDRESS__ #endif Once hwaddress sanitizer was added to GCC, however, a separate define was created, __SANITIZE_HWADDRESS__. The kernel is expecting to find __SANITIZE_ADDRESS__ in either case, though, and the existing string macros break on supported architectures: #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ !defined(__SANITIZE_ADDRESS__) where as other architectures (like arm32) have no idea about hwaddress sanitizer and just check for __SANITIZE_ADDRESS__: #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) This would lead to compiler foritfy self-test warnings when building with CONFIG_KASAN_SW_TAGS=y: warning: unsafe memmove() usage lacked '__read_overflow2' symbol in lib/test_fortify/read_overflow2-memmove.c warning: unsafe memcpy() usage lacked '__write_overflow' symbol in lib/test_fortify/write_overflow-memcpy.c ... Sort this out by also defining __SANITIZE_ADDRESS__ in GCC under the hwaddress sanitizer. Suggested-by: Arnd Bergmann <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Will Deacon <[email protected]> Cc: Arvind Sankar <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Reviewed-by: Marco Elver <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 47c6624 commit 9a48e75

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/compiler-gcc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@
121121
#define __no_sanitize_coverage
122122
#endif
123123

124+
/*
125+
* Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel,
126+
* matching the defines used by Clang.
127+
*/
128+
#ifdef __SANITIZE_HWADDRESS__
129+
#define __SANITIZE_ADDRESS__
130+
#endif
131+
124132
/*
125133
* Turn individual warnings and errors on and off locally, depending
126134
* on version.

0 commit comments

Comments
 (0)