From: Alice Ryhl Date: Wed, 8 Apr 2026 08:32:17 +0000 (+0000) Subject: rust: kasan: add support for Software Tag-Based KASAN X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=72d33b8bfeacbfdccf2cda4650e8e002def036f8;p=thirdparty%2Fkernel%2Flinux.git rust: kasan: add support for Software Tag-Based KASAN 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. The kasan makefile uses different names for the flags depending on whether CC is clang or gcc, but as we require that CC is clang when using KASAN, we do not need to try to handle mixed gcc/llvm builds when Rust is enabled. Link: https://github.com/rust-lang/rust/pull/153049 [1] Reviewed-by: Danilo Krummrich Signed-off-by: Alice Ryhl Reviewed-by: Gary Guo Link: https://patch.msgid.link/20260408-kasan-rust-sw-tags-v3-2-e07964d14363@google.com Signed-off-by: Miguel Ojeda --- diff --git a/init/Kconfig b/init/Kconfig index 826a7d768ca36..7ef3fa222ca32 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2199,7 +2199,7 @@ config RUST depends on !CFI || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC select CFI_ICALL_NORMALIZE_INTEGERS if CFI depends on !KASAN || CC_IS_CLANG - depends on !KASAN_SW_TAGS + depends on !KASAN_SW_TAGS || RUSTC_VERSION >= 109600 help Enables Rust support in the kernel. diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 0ba2aac3b8dc0..91504e81247a9 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