[PATCH v3 0/2] rust: add support for Software Tag-Based KASAN

0 views
Skip to first unread message

Alice Ryhl

unread,
Apr 8, 2026, 4:32:28 AM (2 days ago) Apr 8
to Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev, Alice Ryhl
Please see the commit message of the last patch for details.

Signed-off-by: Alice Ryhl <alic...@google.com>
---
Changes in v3:
- Disallow mixing kasan with gcc.
- Link to v2: https://lore.kernel.org/r/20260331-kasan-rust-sw...@google.com

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...@google.com

---
Alice Ryhl (2):
rust: kasan: KASAN+RUST requires clang
rust: kasan: add support for Software Tag-Based KASAN

init/Kconfig | 3 ++-
scripts/Makefile.kasan | 2 --
2 files changed, 2 insertions(+), 3 deletions(-)
---
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
change-id: 20260325-kasan-rust-sw-tags-c5afff30e63a

Best regards,
--
Alice Ryhl <alic...@google.com>

Alice Ryhl

unread,
Apr 8, 2026, 4:32:29 AM (2 days ago) Apr 8
to Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev, Alice Ryhl
Kernel KASAN involves passing various llvm/gcc specific arguments to
the C and Rust compiler. Since these arguments differ between llvm and
gcc, it's not safe to mix an llvm-based rustc with a gcc build when
kasan is enabled.

Signed-off-by: Alice Ryhl <alic...@google.com>
---
init/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/init/Kconfig b/init/Kconfig
index 444ce811ea67..1d41c7c5e986 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2179,6 +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 || CC_IS_CLANG
depends on !KASAN_SW_TAGS
depends on !(MITIGATION_RETHUNK && KASAN) || RUSTC_VERSION >= 108300
help

--
2.53.0.1213.gd9a14994de-goog

Alice Ryhl

unread,
Apr 8, 2026, 4:32:31 AM (2 days ago) Apr 8
to Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev, Alice Ryhl
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 <da...@kernel.org>
Signed-off-by: Alice Ryhl <alic...@google.com>
---
init/Kconfig | 2 +-
scripts/Makefile.kasan | 2 --
2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index 1d41c7c5e986..d2edb1dbd2f2 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2180,7 +2180,7 @@ config RUST
select CFI_ICALL_NORMALIZE_INTEGERS if CFI
depends on !CALL_PADDING || RUSTC_VERSION >= 108100
depends on !KASAN || CC_IS_CLANG
- 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


--
2.53.0.1213.gd9a14994de-goog

Miguel Ojeda

unread,
Apr 8, 2026, 4:41:11 AM (2 days ago) Apr 8
to Alice Ryhl, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
On Wed, Apr 8, 2026 at 10:32 AM Alice Ryhl <alic...@google.com> wrote:
>
> Kernel KASAN involves passing various llvm/gcc specific arguments to
> the C and Rust compiler. Since these arguments differ between llvm and
> gcc, it's not safe to mix an llvm-based rustc with a gcc build when
> kasan is enabled.
>
> Signed-off-by: Alice Ryhl <alic...@google.com>

We probably want:

Cc: sta...@vger.kernel.org
Fixes: e3117404b411 ("kbuild: rust: Enable KASAN support")

Cheers,
Miguel

Gary Guo

unread,
Apr 8, 2026, 7:55:08 AM (2 days ago) Apr 8
to Alice Ryhl, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
On Wed Apr 8, 2026 at 9:32 AM BST, Alice Ryhl wrote:
> Please see the commit message of the last patch for details.
>
> Signed-off-by: Alice Ryhl <alic...@google.com>
> ---
> Changes in v3:
> - Disallow mixing kasan with gcc.
> - Link to v2: https://lore.kernel.org/r/20260331-kasan-rust-sw...@google.com
>
> 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...@google.com
>
> ---

Reviewed-by: Gary Guo <ga...@garyguo.net>
Reply all
Reply to author
Forward
0 new messages