mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN
@ 2026-04-08  8:32 Alice Ryhl
  2026-04-08  8:32 ` [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang Alice Ryhl
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Alice Ryhl @ 2026-04-08  8:32 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

Please see the commit message of the last patch for details.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Changes in v3:
- Disallow mixing kasan with gcc.
- Link to v2: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@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-tags-v1-0-7d3a765a72aa@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 <aliceryhl@google.com>


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

* [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-04-08  8:32 [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
@ 2026-04-08  8:32 ` Alice Ryhl
  2026-04-08  8:40   ` Miguel Ojeda
  2026-05-27 13:58   ` Mark Brown
  2026-04-08  8:32 ` [PATCH v3 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Alice Ryhl @ 2026-04-08  8:32 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

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 <aliceryhl@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


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

* [PATCH v3 2/2] rust: kasan: add support for Software Tag-Based KASAN
  2026-04-08  8:32 [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
  2026-04-08  8:32 ` [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang Alice Ryhl
@ 2026-04-08  8:32 ` Alice Ryhl
  2026-04-08 11:55 ` [PATCH v3 0/2] rust: " Gary Guo
  2026-05-27  8:53 ` Miguel Ojeda
  3 siblings, 0 replies; 11+ messages in thread
From: Alice Ryhl @ 2026-04-08  8:32 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].

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 <dakr@kernel.org>
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 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


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

* Re: [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-04-08  8:32 ` [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang Alice Ryhl
@ 2026-04-08  8:40   ` Miguel Ojeda
  2026-05-27 13:58   ` Mark Brown
  1 sibling, 0 replies; 11+ messages in thread
From: Miguel Ojeda @ 2026-04-08  8:40 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, Danilo Krummrich, linux-kernel,
	kasan-dev, rust-for-linux, llvm

On Wed, Apr 8, 2026 at 10:32 AM Alice Ryhl <aliceryhl@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 <aliceryhl@google.com>

We probably want:

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

Cheers,
Miguel

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

* Re: [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN
  2026-04-08  8:32 [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
  2026-04-08  8:32 ` [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang Alice Ryhl
  2026-04-08  8:32 ` [PATCH v3 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
@ 2026-04-08 11:55 ` Gary Guo
  2026-05-27  8:53 ` Miguel Ojeda
  3 siblings, 0 replies; 11+ messages in thread
From: Gary Guo @ 2026-04-08 11:55 UTC (permalink / raw)
  To: Alice Ryhl, 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

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 <aliceryhl@google.com>
> ---
> Changes in v3:
> - Disallow mixing kasan with gcc.
> - Link to v2: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@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-tags-v1-0-7d3a765a72aa@google.com
>
> ---

Reviewed-by: Gary Guo <gary@garyguo.net>

> 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,


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

* Re: [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN
  2026-04-08  8:32 [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
                   ` (2 preceding siblings ...)
  2026-04-08 11:55 ` [PATCH v3 0/2] rust: " Gary Guo
@ 2026-05-27  8:53 ` Miguel Ojeda
  3 siblings, 0 replies; 11+ messages in thread
From: Miguel Ojeda @ 2026-05-27  8:53 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, Danilo Krummrich, linux-kernel,
	kasan-dev, rust-for-linux, llvm

On Wed, Apr 8, 2026 at 10:32 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
>       rust: kasan: KASAN+RUST requires clang
>       rust: kasan: add support for Software Tag-Based KASAN

Applied to `rust-next` -- thanks everyone!

If KASAN/Kbuild doesn't want that I take it, then please let me know,
happy to drop them, in which case:

  Acked-by: Miguel Ojeda <ojeda@kernel.org>

Otherwise, I will keep them -- Acked-by's appreciated, of course!

Cheers,
Miguel

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

* Re: [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-04-08  8:32 ` [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang Alice Ryhl
  2026-04-08  8:40   ` Miguel Ojeda
@ 2026-05-27 13:58   ` Mark Brown
  2026-05-27 15:07     ` Miguel Ojeda
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Brown @ 2026-05-27 13:58 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, Danilo Krummrich, linux-kernel,
	kasan-dev, rust-for-linux, llvm

[-- Attachment #1: Type: text/plain, Size: 479 bytes --]

On Wed, Apr 08, 2026 at 08:32:16AM +0000, Alice Ryhl 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.

FWIW this has the effect of turning off rust for an allmodconfig unless
you're using LLVM=1.  That's probably the right thing to do but it means
you might've lost a bunch of coverage.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-05-27 13:58   ` Mark Brown
@ 2026-05-27 15:07     ` Miguel Ojeda
  2026-05-27 15:13       ` Mark Brown
  0 siblings, 1 reply; 11+ messages in thread
From: Miguel Ojeda @ 2026-05-27 15:07 UTC (permalink / raw)
  To: Mark Brown
  Cc: 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-kernel, kasan-dev, rust-for-linux, llvm

On Wed, May 27, 2026 at 3:58 PM Mark Brown <broonie@kernel.org> wrote:
>
> FWIW this has the effect of turning off rust for an allmodconfig unless
> you're using LLVM=1.  That's probably the right thing to do but it means
> you might've lost a bunch of coverage.

Yeah :/ Thanks for the warning.

Hmm... Do you happen to have "exceptions to allmodconfig" for
linux-next? i.e. configs that you disable after `make ...
allmodconfig`?

Cheers,
Miguel

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

* Re: [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-05-27 15:07     ` Miguel Ojeda
@ 2026-05-27 15:13       ` Mark Brown
  2026-05-27 15:27         ` Miguel Ojeda
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Brown @ 2026-05-27 15:13 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: 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-kernel, kasan-dev, rust-for-linux, llvm

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

On Wed, May 27, 2026 at 05:07:30PM +0200, Miguel Ojeda wrote:
> On Wed, May 27, 2026 at 3:58 PM Mark Brown <broonie@kernel.org> wrote:

> > FWIW this has the effect of turning off rust for an allmodconfig unless
> > you're using LLVM=1.  That's probably the right thing to do but it means
> > you might've lost a bunch of coverage.

> Yeah :/ Thanks for the warning.

> Hmm... Do you happen to have "exceptions to allmodconfig" for
> linux-next? i.e. configs that you disable after `make ...
> allmodconfig`?

No, I just started building it with LLVM=1 though.  We'll see if
anything fun happens with the different set of diagnostics, it's
currently clean so we're OK right now.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-05-27 15:13       ` Mark Brown
@ 2026-05-27 15:27         ` Miguel Ojeda
  2026-05-27 16:08           ` Mark Brown
  0 siblings, 1 reply; 11+ messages in thread
From: Miguel Ojeda @ 2026-05-27 15:27 UTC (permalink / raw)
  To: Mark Brown
  Cc: 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-kernel, kasan-dev, rust-for-linux, llvm

On Wed, May 27, 2026 at 5:13 PM Mark Brown <broonie@kernel.org> wrote:
>
> No, I just started building it with LLVM=1 though.  We'll see if
> anything fun happens with the different set of diagnostics, it's
> currently clean so we're OK right now.

Sounds good, thanks!

(`LLVM=1` is what we (or at least I) test the most by far, but it is
true that Linux distributions out there use the GCC (and thus, for
now, mixed GCC+LLVM) builds...)

Cheers,
Miguel

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

* Re: [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang
  2026-05-27 15:27         ` Miguel Ojeda
@ 2026-05-27 16:08           ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2026-05-27 16:08 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: 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-kernel, kasan-dev, rust-for-linux, llvm

[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

On Wed, May 27, 2026 at 05:27:18PM +0200, Miguel Ojeda wrote:
> On Wed, May 27, 2026 at 5:13 PM Mark Brown <broonie@kernel.org> wrote:

> > No, I just started building it with LLVM=1 though.  We'll see if
> > anything fun happens with the different set of diagnostics, it's
> > currently clean so we're OK right now.

> Sounds good, thanks!

> (`LLVM=1` is what we (or at least I) test the most by far, but it is
> true that Linux distributions out there use the GCC (and thus, for
> now, mixed GCC+LLVM) builds...)

Yeah, plus I'm not aware of comparable build coverage for GCC to what we
have for clang which makes me a bit worried about doing something that
lowers coverage.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-08  8:32 [PATCH v3 0/2] rust: add support for Software Tag-Based KASAN Alice Ryhl
2026-04-08  8:32 ` [PATCH v3 1/2] rust: kasan: KASAN+RUST requires clang Alice Ryhl
2026-04-08  8:40   ` Miguel Ojeda
2026-05-27 13:58   ` Mark Brown
2026-05-27 15:07     ` Miguel Ojeda
2026-05-27 15:13       ` Mark Brown
2026-05-27 15:27         ` Miguel Ojeda
2026-05-27 16:08           ` Mark Brown
2026-04-08  8:32 ` [PATCH v3 2/2] rust: kasan: add support for Software Tag-Based KASAN Alice Ryhl
2026-04-08 11:55 ` [PATCH v3 0/2] rust: " Gary Guo
2026-05-27  8:53 ` Miguel Ojeda

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

all inboxes | Powered by JetHome®