lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAFhGd8qku6wkpqNCq+KpM4TMh-djVQW4UEdXON1Tk1BRtN8V6g@mail.gmail.com>
Date: Tue, 2 Sep 2025 16:09:04 -0700
From: Justin Stitt <justinstitt@...gle.com>
To: Nathan Chancellor <nathan@...nel.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>, Andrey Ryabinin <ryabinin.a.a@...il.com>, 
	Alexander Potapenko <glider@...gle.com>, Andrey Konovalov <andreyknvl@...il.com>, 
	Dmitry Vyukov <dvyukov@...gle.com>, Marco Elver <elver@...gle.com>, 
	Nick Desaulniers <nick.desaulniers+lkml@...il.com>, Bill Wendling <morbo@...gle.com>, 
	kasan-dev@...glegroups.com, llvm@...ts.linux.dev, 
	linux-kernel@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH] compiler-clang.h: Define __SANITIZE_*__ macros only when undefined

On Tue, Sep 2, 2025 at 3:49 PM Nathan Chancellor <nathan@...nel.org> wrote:
>
> Clang 22 recently added support for defining __SANITIZE__ macros similar
> to GCC [1], which causes warnings (or errors with CONFIG_WERROR=y or
> W=e) with the existing defines that the kernel creates to emulate this
> behavior with existing clang versions.
>
>   In file included from <built-in>:3:
>   In file included from include/linux/compiler_types.h:171:
>   include/linux/compiler-clang.h:37:9: error: '__SANITIZE_THREAD__' macro redefined [-Werror,-Wmacro-redefined]
>      37 | #define __SANITIZE_THREAD__
>         |         ^
>   <built-in>:352:9: note: previous definition is here
>     352 | #define __SANITIZE_THREAD__ 1
>         |         ^
>
> Refactor compiler-clang.h to only define the sanitizer macros when they
> are undefined and adjust the rest of the code to use these macros for
> checking if the sanitizers are enabled, clearing up the warnings and
> allowing the kernel to easily drop these defines when the minimum
> supported version of LLVM for building the kernel becomes 22.0.0 or
> newer.
>
> Cc: stable@...r.kernel.org
> Link: https://github.com/llvm/llvm-project/commit/568c23bbd3303518c5056d7f03444dae4fdc8a9c [1]
> Signed-off-by: Nathan Chancellor <nathan@...nel.org>

Reviewed-by: Justin Stitt <justinstitt@...gle.com>

> ---
> Andrew, would it be possible to take this via mm-hotfixes?
> ---
>  include/linux/compiler-clang.h | 29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
> index fa4ffe037bc7..8720a0705900 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -18,23 +18,42 @@
>  #define KASAN_ABI_VERSION 5
>
>  /*
> + * Clang 22 added preprocessor macros to match GCC, in hopes of eventually
> + * dropping __has_feature support for sanitizers:
> + * https://github.com/llvm/llvm-project/commit/568c23bbd3303518c5056d7f03444dae4fdc8a9c
> + * Create these macros for older versions of clang so that it is easy to clean
> + * up once the minimum supported version of LLVM for building the kernel always
> + * creates these macros.
> + *
>   * Note: Checking __has_feature(*_sanitizer) is only true if the feature is
>   * enabled. Therefore it is not required to additionally check defined(CONFIG_*)
>   * to avoid adding redundant attributes in other configurations.
>   */
> +#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
> +#define __SANITIZE_ADDRESS__
> +#endif
> +#if __has_feature(hwaddress_sanitizer) && !defined(__SANITIZE_HWADDRESS__)
> +#define __SANITIZE_HWADDRESS__
> +#endif
> +#if __has_feature(thread_sanitizer) && !defined(__SANITIZE_THREAD__)
> +#define __SANITIZE_THREAD__
> +#endif
>
> -#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
> -/* Emulate GCC's __SANITIZE_ADDRESS__ flag */
> +/*
> + * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel.
> + */
> +#ifdef __SANITIZE_HWADDRESS__
>  #define __SANITIZE_ADDRESS__
> +#endif
> +
> +#ifdef __SANITIZE_ADDRESS__
>  #define __no_sanitize_address \
>                 __attribute__((no_sanitize("address", "hwaddress")))
>  #else
>  #define __no_sanitize_address
>  #endif
>
> -#if __has_feature(thread_sanitizer)
> -/* emulate gcc's __SANITIZE_THREAD__ flag */
> -#define __SANITIZE_THREAD__
> +#ifdef __SANITIZE_THREAD__
>  #define __no_sanitize_thread \
>                 __attribute__((no_sanitize("thread")))
>  #else
>
> ---
> base-commit: b320789d6883cc00ac78ce83bccbfe7ed58afcf0
> change-id: 20250902-clang-update-sanitize-defines-845000c29d2c
>
> Best regards,
> --
> Nathan Chancellor <nathan@...nel.org>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ