public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: add support for Software Tag-Based KASAN
@ 2026-03-25  9:26 Alice Ryhl
  2026-03-25  9:26 ` [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover Alice Ryhl
  2026-03-25  9:26 ` [PATCH 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
  0 siblings, 2 replies; 9+ messages in thread
From: Alice Ryhl @ 2026-03-25  9:26 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
	Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-kernel,
	kasan-dev, rust-for-linux, llvm, Alice Ryhl

Since my kernel-hwaddress patch to rustc [1] is now landed, I'm sending
this series to enable support for it in the kernel.

[1]: https://github.com/rust-lang/rust/pull/153049

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Alice Ryhl (2):
      rust: kasan: do not pass -Zsanitizer-recover
      rust: kasan: add support for Software Tag-Based KASAN

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

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
  2026-03-25  9:26 [PATCH 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
@ 2026-03-25  9:26 ` Alice Ryhl
  2026-03-25 11:06   ` Danilo Krummrich
  2026-03-25  9:26 ` [PATCH 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
  1 sibling, 1 reply; 9+ messages in thread
From: Alice Ryhl @ 2026-03-25  9:26 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
	Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-kernel,
	kasan-dev, rust-for-linux, llvm, Alice Ryhl

We do not pass -fsanitize-recover to clang, so for consistency we should
not pass -Zsanitizer-recover to rustc. Thus, remove these flags.

Fixes: e3117404b411 ("kbuild: rust: Enable KASAN support")
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 scripts/Makefile.kasan | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 0ba2aac3b8dc..9a9033096c88 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -49,7 +49,6 @@ CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \
 # The minimum supported `rustc` version has a minimum supported LLVM
 # version late enough that we can assume support for -asan-mapping-offset.
 RUSTFLAGS_KASAN := -Zsanitizer=kernel-address \
-		   -Zsanitizer-recover=kernel-address \
 		   -Cllvm-args=-asan-mapping-offset=$(KASAN_SHADOW_OFFSET)
 
 # Now, add other parameters enabled similarly in GCC, Clang, and rustc.
@@ -73,8 +72,7 @@ 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
+RUSTFLAGS_KASAN := -Zsanitizer=kernel-hwaddress
 
 ifdef CONFIG_KASAN_INLINE
 	kasan_params += hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)

-- 
2.53.0.1018.g2bb0e51243-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] rust: kasan: add support for Software Tag-Based KASAN
  2026-03-25  9:26 [PATCH 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
  2026-03-25  9:26 ` [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover Alice Ryhl
@ 2026-03-25  9:26 ` Alice Ryhl
  2026-03-25 11:09   ` Danilo Krummrich
  1 sibling, 1 reply; 9+ messages in thread
From: Alice Ryhl @ 2026-03-25  9:26 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
	Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-kernel,
	kasan-dev, rust-for-linux, llvm, 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].

Link: https://github.com/rust-lang/rust/pull/153049 [1]
Signed-off-by: Alice Ryhl <aliceryhl@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 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 9a9033096c88..3833e0b3b857 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -70,8 +70,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
 
 ifdef CONFIG_KASAN_INLINE

-- 
2.53.0.1018.g2bb0e51243-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
  2026-03-25  9:26 ` [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover Alice Ryhl
@ 2026-03-25 11:06   ` Danilo Krummrich
  2026-03-25 11:47     ` Alice Ryhl
  0 siblings, 1 reply; 9+ messages in thread
From: Danilo Krummrich @ 2026-03-25 11:06 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: 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, linux-kernel, kasan-dev,
	rust-for-linux, llvm

On Wed Mar 25, 2026 at 10:26 AM CET, Alice Ryhl wrote:
> We do not pass -fsanitize-recover to clang, so for consistency we should
> not pass -Zsanitizer-recover to rustc. Thus, remove these flags.

Isn't this because clang forces it regardless? Is this true for rustc as well?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] rust: kasan: add support for Software Tag-Based KASAN
  2026-03-25  9:26 ` [PATCH 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
@ 2026-03-25 11:09   ` Danilo Krummrich
  0 siblings, 0 replies; 9+ messages in thread
From: Danilo Krummrich @ 2026-03-25 11:09 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: 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, linux-kernel, kasan-dev,
	rust-for-linux, llvm

On 3/25/26 10:26 AM, Alice Ryhl 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].
> 
> Link: https://github.com/rust-lang/rust/pull/153049 [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
  2026-03-25 11:06   ` Danilo Krummrich
@ 2026-03-25 11:47     ` Alice Ryhl
  2026-03-25 14:04       ` Danilo Krummrich
  0 siblings, 1 reply; 9+ messages in thread
From: Alice Ryhl @ 2026-03-25 11:47 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: 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, linux-kernel, kasan-dev,
	rust-for-linux, llvm

On Wed, Mar 25, 2026 at 12:06:50PM +0100, Danilo Krummrich wrote:
> On Wed Mar 25, 2026 at 10:26 AM CET, Alice Ryhl wrote:
> > We do not pass -fsanitize-recover to clang, so for consistency we should
> > not pass -Zsanitizer-recover to rustc. Thus, remove these flags.
> 
> Isn't this because clang forces it regardless? Is this true for rustc as well?

I forgot to mention this in commit, but I'm actually a bit confused
about the situation here. If clang forces it somehow, how? I don't think
rustc does anything like that, but not sure. If it doesn't, but clang
does, then maybe rustc should too? Depends on how that happens.

Alice

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
  2026-03-25 11:47     ` Alice Ryhl
@ 2026-03-25 14:04       ` Danilo Krummrich
  2026-03-25 14:30         ` Gary Guo
  0 siblings, 1 reply; 9+ messages in thread
From: Danilo Krummrich @ 2026-03-25 14:04 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: 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, linux-kernel, kasan-dev,
	rust-for-linux, llvm

On Wed Mar 25, 2026 at 12:47 PM CET, Alice Ryhl wrote:
> On Wed, Mar 25, 2026 at 12:06:50PM +0100, Danilo Krummrich wrote:
>> On Wed Mar 25, 2026 at 10:26 AM CET, Alice Ryhl wrote:
>> > We do not pass -fsanitize-recover to clang, so for consistency we should
>> > not pass -Zsanitizer-recover to rustc. Thus, remove these flags.
>> 
>> Isn't this because clang forces it regardless? Is this true for rustc as well?
>
> I forgot to mention this in commit, but I'm actually a bit confused
> about the situation here. If clang forces it somehow, how?

I previously had a very brief look at the source code and came across this [1],
where

	static const SanitizerMask AlwaysRecoverable = SanitizerKind::KernelAddress |
	                                               SanitizerKind::KernelHWAddress |
	                                               SanitizerKind::KCFI;

But again, I only had a very brief look and it might well be that I got this
wrong.

[1] https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/SanitizerArgs.cpp#L750

> I don't think rustc does anything like that, but not sure. If it doesn't, but
> clang does, then maybe rustc should too? Depends on how that happens.
>
> Alice


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
  2026-03-25 14:04       ` Danilo Krummrich
@ 2026-03-25 14:30         ` Gary Guo
  2026-03-27 11:04           ` Alice Ryhl
  0 siblings, 1 reply; 9+ messages in thread
From: Gary Guo @ 2026-03-25 14:30 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl
  Cc: 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, linux-kernel, kasan-dev,
	rust-for-linux, llvm

On Wed Mar 25, 2026 at 2:04 PM GMT, Danilo Krummrich wrote:
> On Wed Mar 25, 2026 at 12:47 PM CET, Alice Ryhl wrote:
>> On Wed, Mar 25, 2026 at 12:06:50PM +0100, Danilo Krummrich wrote:
>>> On Wed Mar 25, 2026 at 10:26 AM CET, Alice Ryhl wrote:
>>> > We do not pass -fsanitize-recover to clang, so for consistency we should
>>> > not pass -Zsanitizer-recover to rustc. Thus, remove these flags.
>>> 
>>> Isn't this because clang forces it regardless? Is this true for rustc as well?
>>
>> I forgot to mention this in commit, but I'm actually a bit confused
>> about the situation here. If clang forces it somehow, how?
>
> I previously had a very brief look at the source code and came across this [1],
> where
>
> 	static const SanitizerMask AlwaysRecoverable = SanitizerKind::KernelAddress |
> 	                                               SanitizerKind::KernelHWAddress |
> 	                                               SanitizerKind::KCFI;
>
> But again, I only had a very brief look and it might well be that I got this
> wrong.
>
> [1] https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/SanitizerArgs.cpp#L750
>
>> I don't think rustc does anything like that, but not sure. If it doesn't, but
>> clang does, then maybe rustc should too? Depends on how that happens.

It looks like there's no similar logic, and Rustc is passing recoverable
settings based on the command line options:

https://github.com/rust-lang/rust/blob/8a703520e80d87d4423c01f9d4fbc9e5f6533a02/compiler/rustc_codegen_llvm/src/back/write.rs#L644

Best,
Gary


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
  2026-03-25 14:30         ` Gary Guo
@ 2026-03-27 11:04           ` Alice Ryhl
  0 siblings, 0 replies; 9+ messages in thread
From: Alice Ryhl @ 2026-03-27 11:04 UTC (permalink / raw)
  To: Gary Guo
  Cc: Danilo Krummrich, Andrey Ryabinin, Alexander Potapenko,
	Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, linux-kernel, kasan-dev,
	rust-for-linux, llvm

On Wed, Mar 25, 2026 at 3:30 PM Gary Guo <gary@garyguo.net> wrote:
>
> On Wed Mar 25, 2026 at 2:04 PM GMT, Danilo Krummrich wrote:
> > On Wed Mar 25, 2026 at 12:47 PM CET, Alice Ryhl wrote:
> >> On Wed, Mar 25, 2026 at 12:06:50PM +0100, Danilo Krummrich wrote:
> >>> On Wed Mar 25, 2026 at 10:26 AM CET, Alice Ryhl wrote:
> >>> > We do not pass -fsanitize-recover to clang, so for consistency we should
> >>> > not pass -Zsanitizer-recover to rustc. Thus, remove these flags.
> >>>
> >>> Isn't this because clang forces it regardless? Is this true for rustc as well?
> >>
> >> I forgot to mention this in commit, but I'm actually a bit confused
> >> about the situation here. If clang forces it somehow, how?
> >
> > I previously had a very brief look at the source code and came across this [1],
> > where
> >
> >       static const SanitizerMask AlwaysRecoverable = SanitizerKind::KernelAddress |
> >                                                      SanitizerKind::KernelHWAddress |
> >                                                      SanitizerKind::KCFI;
> >
> > But again, I only had a very brief look and it might well be that I got this
> > wrong.
> >
> > [1] https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/SanitizerArgs.cpp#L750
> >
> >> I don't think rustc does anything like that, but not sure. If it doesn't, but
> >> clang does, then maybe rustc should too? Depends on how that happens.
>
> It looks like there's no similar logic, and Rustc is passing recoverable
> settings based on the command line options:
>
> https://github.com/rust-lang/rust/blob/8a703520e80d87d4423c01f9d4fbc9e5f6533a02/compiler/rustc_codegen_llvm/src/back/write.rs#L644

Based on
https://lore.kernel.org/all/202603271853.RhfDTdOp-lkp@intel.com/
it seems like you all are right. There is a rustc/clang difference here.

Alice

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-27 11:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25  9:26 [PATCH 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
2026-03-25  9:26 ` [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover Alice Ryhl
2026-03-25 11:06   ` Danilo Krummrich
2026-03-25 11:47     ` Alice Ryhl
2026-03-25 14:04       ` Danilo Krummrich
2026-03-25 14:30         ` Gary Guo
2026-03-27 11:04           ` Alice Ryhl
2026-03-25  9:26 ` [PATCH 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
2026-03-25 11:09   ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox