Re: [PATCH v2] rust: kasan: add support for Software Tag-Based KASAN
From: Alice Ryhl
Date: Wed Apr 01 2026 - 05:21:33 EST
On Tue, Mar 31, 2026 at 2:09 PM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> This adds support for Software Tag-Based KASAN (KASAN_SW_TAGS) when
> CONFIG_RUST is enabled. This requires that rustc includes support for
> the kernel-hwaddress sanitizer, which is available since 1.96.0 [1].
>
> Unlike with clang, we need to pass -Zsanitizer-recover in addition to
> -Zsanitizer because the option is not implied automatically.
>
> Link: https://github.com/rust-lang/rust/pull/153049 [1]
> Reviewed-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> ---
> Changes in v2:
> - Drop the first patch for -Zsanitizer-recover, and mention why in
> commit message for remaining patch.
> - Pick up tags.
> - Link to v1: https://lore.kernel.org/r/20260325-kasan-rust-sw-tags-v1-0-7d3a765a72aa@xxxxxxxxxx
> ---
> init/Kconfig | 2 +-
> scripts/Makefile.kasan | 2 --
> 2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/init/Kconfig b/init/Kconfig
> index 444ce811ea67..545cbe889a52 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -2179,7 +2179,7 @@ config RUST
> depends on !CFI || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
> select CFI_ICALL_NORMALIZE_INTEGERS if CFI
> depends on !CALL_PADDING || RUSTC_VERSION >= 108100
> - depends on !KASAN_SW_TAGS
> + depends on !KASAN_SW_TAGS || RUSTC_VERSION >= 109600
> depends on !(MITIGATION_RETHUNK && KASAN) || RUSTC_VERSION >= 108300
> help
> Enables Rust support in the kernel.
> diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
> index 0ba2aac3b8dc..91504e81247a 100644
> --- a/scripts/Makefile.kasan
> +++ b/scripts/Makefile.kasan
> @@ -71,8 +71,6 @@ ifdef CONFIG_KASAN_SW_TAGS
>
> CFLAGS_KASAN := -fsanitize=kernel-hwaddress
>
> -# This sets flags that will enable SW_TAGS KASAN once enabled in Rust. These
> -# will not work today, and is guarded against in dependencies for CONFIG_RUST.
> RUSTFLAGS_KASAN := -Zsanitizer=kernel-hwaddress \
> -Zsanitizer-recover=kernel-hwaddress
Sashiko is asking what happens when GCC is enabled. I think we just
don't want this enabled together with GCC. Miguel how do we usually
handle such cases? I imagine we have quite a few options that are
probably not compatible with gcc, but I'm not sure we explicitly list
all those cases in Kconfig.
Alice