• K
    compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer · 9a48e756
    Kees Cook 提交于
    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: NArnd Bergmann <arnd@arndb.de>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Will Deacon <will@kernel.org>
    Cc: Arvind Sankar <nivedita@alum.mit.edu>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: llvm@lists.linux.dev
    Signed-off-by: NKees Cook <keescook@chromium.org>
    Reviewed-by: NNathan Chancellor <nathan@kernel.org>
    Acked-by: NMiguel Ojeda <ojeda@kernel.org>
    Reviewed-by: NMarco Elver <elver@google.com>
    Link: https://lore.kernel.org/r/20211020200039.170424-1-keescook@chromium.org
    9a48e756
compiler-gcc.h 4.6 KB