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

3 views
Skip to first unread message

Alice Ryhl

unread,
Mar 25, 2026, 5:27:04 AMMar 25
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
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 <alic...@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 <alic...@google.com>

Alice Ryhl

unread,
Mar 25, 2026, 5:27:06 AMMar 25
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
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 <alic...@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

Alice Ryhl

unread,
Mar 25, 2026, 5:27:08 AMMar 25
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].

Link: https://github.com/rust-lang/rust/pull/153049 [1]
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 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

Danilo Krummrich

unread,
Mar 25, 2026, 7:06:58 AMMar 25
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, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
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?

Danilo Krummrich

unread,
Mar 25, 2026, 7:09:18 AMMar 25
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, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
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 <alic...@google.com>

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

Alice Ryhl

unread,
Mar 25, 2026, 7:47:48 AMMar 25
to Danilo Krummrich, 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-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
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

Danilo Krummrich

unread,
Mar 25, 2026, 10:04:16 AMMar 25
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, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
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

Gary Guo

unread,
Mar 25, 2026, 10:30:33 AMMar 25
to Danilo Krummrich, 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, linux-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
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

Alice Ryhl

unread,
Mar 27, 2026, 7:05:14 AM (14 days ago) Mar 27
to Gary Guo, 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-...@vger.kernel.org, kasa...@googlegroups.com, rust-fo...@vger.kernel.org, ll...@lists.linux.dev
Based on
https://lore.kernel.org/all/202603271853...@intel.com/
it seems like you all are right. There is a rustc/clang difference here.

Alice

kernel test robot

unread,
Mar 27, 2026, 10:28:56 AM (14 days ago) Mar 27
to Alice Ryhl, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt, Miguel Ojeda, ll...@lists.linux.dev, oe-kbu...@lists.linux.dev, 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, Alice Ryhl
Hi Alice,

kernel test robot noticed the following build errors:

[auto build test ERROR on 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681]

url: https://github.com/intel-lab-lkp/linux/commits/Alice-Ryhl/rust-kasan-do-not-pass-Zsanitizer-recover/20260326-213339
base: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
patch link: https://lore.kernel.org/r/20260325-kasan-rust-sw-tags-v1-1-7d3a765a72aa%40google.com
patch subject: [PATCH 1/2] rust: kasan: do not pass -Zsanitizer-recover
config: x86_64-randconfig-071-20260327 (https://download.01.org/0day-ci/archive/20260327/202603271853...@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260327/202603271853...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <l...@intel.com>
| Closes: https://lore.kernel.org/r/202603271853...@intel.com/

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined symbol: __asan_report_load8
>>> referenced by kvec.rs:847 (rust/kernel/alloc/kvec.rs:847)
>>> samples/rust/rust_soc.o:(core::ptr::drop_in_place::<kernel::str::CString>) in archive vmlinux.a
>>> referenced by kvec.rs:847 (rust/kernel/alloc/kvec.rs:847)
>>> samples/rust/rust_soc.o:(core::ptr::drop_in_place::<kernel::str::CString>) in archive vmlinux.a
>>> referenced by aref.rs:170 (rust/kernel/sync/aref.rs:170)
>>> samples/rust/rust_soc.o:(<kernel::driver::Registration<kernel::platform::Adapter<rust_soc::SampleSocDriver>>>::post_unbind_callback) in archive vmlinux.a
>>> referenced 3034 more times
--
>> ld.lld: error: undefined symbol: __asan_report_store8
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>>> samples/rust/rust_soc.o:(<kernel::platform::Adapter<rust_soc::SampleSocDriver>>::probe_callback) in archive vmlinux.a
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>>> samples/rust/rust_soc.o:(<kernel::platform::Adapter<rust_soc::SampleSocDriver>>::probe_callback) in archive vmlinux.a
>>> referenced by rust_configfs.rs:86 (samples/rust/rust_configfs.rs:86)
>>> samples/rust/rust_configfs.o:(<rust_configfs::Configuration as kernel::configfs::GroupOperations>::make_group) in archive vmlinux.a
>>> referenced 1783 more times
--
>> ld.lld: error: undefined symbol: __asan_report_load16
>>> referenced by num.rs:648 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:648)
>>> rust/core.o:(<u128 as core::fmt::Display>::fmt) in archive vmlinux.a
>>> referenced by num.rs:655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:655)
>>> rust/core.o:(<i128 as core::fmt::Display>::fmt) in archive vmlinux.a
>>> referenced by niche_types.rs:100 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/niche_types.rs:100)
>>> rust/core.o:(<core::num::niche_types::NonZeroU128Inner as core::fmt::Debug>::fmt) in archive vmlinux.a
>>> referenced 9 more times
--
>> ld.lld: error: undefined symbol: __asan_report_store16
>>> referenced by option.rs:1279 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1279)
>>> rust/core.o:(<core::num::nonzero::NonZero<u128> as core::str::traits::FromStr>::from_str) in archive vmlinux.a
>>> referenced by option.rs:1279 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1279)
>>> rust/core.o:(<core::num::nonzero::NonZero<i128> as core::str::traits::FromStr>::from_str) in archive vmlinux.a
--
>> ld.lld: error: undefined symbol: __asan_report_load1
>>> referenced by c_str.rs:416 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ffi/c_str.rs:416)
>>> samples/rust/rust_configfs.o:(<kernel::configfs::GroupOperationsVTable<rust_configfs::Configuration, rust_configfs::Child>>::make_group) in archive vmlinux.a
>>> referenced by c_str.rs:416 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ffi/c_str.rs:416)
>>> samples/rust/rust_configfs.o:(<kernel::configfs::GroupOperationsVTable<rust_configfs::Child, rust_configfs::GrandChild>>::make_group) in archive vmlinux.a
>>> referenced by revocable.rs:218 (rust/kernel/revocable.rs:218)
>>> samples/rust/rust_driver_auxiliary.o:(core::ptr::drop_in_place::<kernel::sync::arc::Arc<kernel::revocable::Revocable<kernel::auxiliary::Registration>>>) in archive vmlinux.a
>>> referenced 890 more times
--
>> ld.lld: error: undefined symbol: __asan_report_store4
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>>> samples/rust/rust_configfs.o:(<kernel::configfs::GroupOperationsVTable<rust_configfs::Configuration, rust_configfs::Child>>::make_group) in archive vmlinux.a
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>>> samples/rust/rust_configfs.o:(<kernel::configfs::GroupOperationsVTable<rust_configfs::Child, rust_configfs::GrandChild>>::make_group) in archive vmlinux.a
>>> referenced by result.rs:2050 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:2050)
>>> samples/rust/rust_configfs.o:(<rust_configfs::Configuration as kernel::configfs::GroupOperations>::make_group) in archive vmlinux.a
>>> referenced 539 more times
--
>> ld.lld: error: undefined symbol: __asan_report_store1
>>> referenced by atomic.rs:3845 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:3845)
>>> samples/rust/rust_driver_auxiliary.o:(core::ptr::drop_in_place::<kernel::devres::Devres<kernel::auxiliary::Registration>>) in archive vmlinux.a
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>> >>> samples/rust/rust_driver_auxiliary.o:(pin_init::pin_init_scope::<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error, <kernel::auxiliary::Registration>::new::{closure#0}, core::result::Result<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error>>::{closure#0}) in archive vmlinux.a
>>> referenced by atomic.rs:3845 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:3845)
>>> samples/rust/rust_driver_pci.o:(core::ptr::drop_in_place::<kernel::devres::Devres<kernel::pci::io::Bar<16>>>) in archive vmlinux.a
>>> referenced 356 more times
--
>> ld.lld: error: undefined symbol: __asan_report_load4
>>> referenced by lib.rs:1300 (rust/pin-init/src/lib.rs:1300)
>> >>> samples/rust/rust_driver_auxiliary.o:(pin_init::pin_init_scope::<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error, <kernel::auxiliary::Registration>::new::{closure#0}, core::result::Result<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error>>::{closure#0}) in archive vmlinux.a
>>> referenced by io.rs:261 (rust/kernel/pci/io.rs:261)
>>> samples/rust/rust_driver_pci.o:(core::ptr::drop_in_place::<kernel::devres::Devres<kernel::pci::io::Bar<16>>>) in archive vmlinux.a
>>> referenced by io.rs:261 (rust/kernel/pci/io.rs:261)
>>> samples/rust/rust_driver_pci.o:(core::ptr::drop_in_place::<kernel::sync::arc::Arc<kernel::revocable::Revocable<kernel::pci::io::Bar<16>>>>) in archive vmlinux.a
>>> referenced 320 more times
--
>> ld.lld: error: undefined symbol: __asan_report_store_n
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>> >>> samples/rust/rust_driver_auxiliary.o:(pin_init::pin_init_scope::<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error, <kernel::auxiliary::Registration>::new::{closure#0}, core::result::Result<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error>>::{closure#0}) in archive vmlinux.a
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>> >>> samples/rust/rust_driver_auxiliary.o:(pin_init::pin_init_scope::<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error, <kernel::auxiliary::Registration>::new::{closure#0}, core::result::Result<kernel::devres::Devres<kernel::auxiliary::Registration>, kernel::error::Error>>::{closure#0}) in archive vmlinux.a
>>> referenced by mod.rs:1655 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1655)
>>> samples/rust/rust_driver_pci.o:(<kernel::pci::Adapter<rust_driver_pci::SampleDriver>>::probe_callback) in archive vmlinux.a
>>> referenced 105 more times
--
>> ld.lld: error: undefined symbol: __asan_report_load2
>>> referenced by pci.rs:372 (rust/kernel/pci.rs:372)
>>> samples/rust/rust_driver_pci.o:(<kernel::pci::Adapter<rust_driver_pci::SampleDriver>>::probe_callback) in archive vmlinux.a
>>> referenced by pci.rs:381 (rust/kernel/pci.rs:381)
>>> samples/rust/rust_driver_pci.o:(<kernel::pci::Adapter<rust_driver_pci::SampleDriver>>::probe_callback) in archive vmlinux.a
>>> referenced by pci.rs:372 (rust/kernel/pci.rs:372)
>>> samples/rust/rust_driver_auxiliary.o:(<rust_driver_auxiliary::AuxiliaryDriver as kernel::auxiliary::Driver>::probe) in archive vmlinux.a
>>> referenced 54 more times
--
>> ld.lld: error: undefined symbol: __asan_report_load_n
>>> referenced by mod.rs:3753 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics/mod.rs:3753)
>>> drivers/android/binder/rust_binder_main.o:(<[u8]>::copy_from_slice) in archive vmlinux.a
>>> referenced by mod.rs:3753 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics/mod.rs:3753)
>>> drivers/android/binder/rust_binder_main.o:(<[u8]>::copy_from_slice) in archive vmlinux.a
>>> referenced by mod.rs:864 (/opt/cross/rustc-1.88.0-bindgen-0.72.1/rustup/toolchains/1.88.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:864)
>>> drivers/android/binder/rust_binder_main.o:(<rust_binder_main::range_alloc::tree::Descriptor<rust_binder_main::allocation::AllocationInfo>>::try_change_state::<<rust_binder_main::range_alloc::tree::TreeRangeAllocator<rust_binder_main::allocation::AllocationInfo>>::reservation_abort::{closure#1}, (rust_binder_main::range_alloc::Reservation, kernel::rbtree::RBTreeNodeReservation<(usize, usize), ()>)>) in archive vmlinux.a
>>> referenced 81 more times
..

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

Alice Ryhl

unread,
Mar 31, 2026, 8:09:40 AM (10 days ago) Mar 31
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.

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

Alice Ryhl

unread,
Apr 1, 2026, 5:13:37 AM (9 days ago) Apr 1
to 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, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt
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

Miguel Ojeda

unread,
Apr 1, 2026, 5:46:07 AM (9 days ago) Apr 1
to Alice Ryhl, 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, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt
On Wed, Apr 1, 2026 at 11:13 AM Alice Ryhl <alic...@google.com> wrote:
>
> 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.

For options where it is """OK""" to drop them, one can use the
`bindgen_skip_c_flags` hack in `rust/Makefile` (which is best-effort,
and which we eventually should not have when proper GCC support is
added).

We have `--param=% --param asan-%` there, but to be honest, for things
like that, we may just want to gate it with a `depends on CC_IS_*`
instead.

Cheers,
Miguel
Reply all
Reply to author
Forward
0 new messages