Repository navigation
Add -Zsanitize=kernel-hwaddress - #153049
Merged
Merged
Conversation
Darksonn
force-pushed
the
kasan-sw-tags
branch
from
February 24, 2026 14:52
1191bc5 to
07c2a2a
Compare
This comment has been minimized.
This comment has been minimized.
Darksonn
force-pushed
the
kasan-sw-tags
branch
from
February 24, 2026 15:09
07c2a2a to
9508e21
Compare
This comment has been minimized.
This comment has been minimized.
45 of 80 tasks
Darksonn
force-pushed
the
kasan-sw-tags
branch
from
February 27, 2026 10:57
9508e21 to
c7a338e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Darksonn
commented
Mar 7, 2026
Comment on lines
+127
to
+135
| // KHWASAN: In LLVM versions prior to 21.1.0, the HWAddressSanitizer pass incorrectly | ||
| // ignores the pass-specific `CompileKernel` flag and only looks at the global command-line | ||
| // flag `-hwasan-kernel`. To work around this, pass `-hwasan-kernel` on the relevant LLVM | ||
| // versions. | ||
| // | ||
| // Fixed by: [HWASan][bugfix] Fix kernel check in ShadowMapping::init (#142226). | ||
| if sess.sanitizers().contains(SanitizerSet::KERNELHWADDRESS) && get_version() < (21, 1, 0) { | ||
| add("-hwasan-kernel", false); | ||
| } |
Member
Author
There was a problem hiding this comment.
@fmayer Is this reasonable a reasonable fix for rustc to work around the lack of llvm/llvm-project#142226? Or do you think I should pass this on all versions? Thanks!
This comment has been minimized.
This comment has been minimized.
Darksonn
marked this pull request as ready for review
March 7, 2026 16:19
Collaborator
|
Some changes occurred in cfg and check-cfg configuration cc @Urgau Some changes occurred in tests/ui/sanitizer cc @rcvalle Some changes occurred in src/tools/compiletest cc @jieyouxu Some changes occurred in tests/codegen-llvm/sanitizer cc @rcvalle Some changes occurred in compiler/rustc_attr_parsing |
Collaborator
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
2 of 3 tasks
Member
This comment has been minimized.
This comment has been minimized.
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Mar 25, 2026
Add `-Zsanitize=kernel-hwaddress` The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS` that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust. One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable. Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it. MCP: rust-lang/compiler-team#975 Tracking issue: rust-lang#154171 cc @rcvalle @maurer @ojeda
rust-bors Bot
pushed a commit
that referenced
this pull request
Mar 25, 2026
Rollup of 6 pull requests Successful merges: - #154004 (`Alignment`: move from `ptr` to `mem` and rename `as_nonzero` to `as_nonzero_usize`) - #153049 (Add `-Zsanitize=kernel-hwaddress`) - #154269 (miri recursive validation: only check one layer deep) - #154112 (some `tests/ui/macros` cleanup) - #154131 (begin `tests/ui/structs-enums` cleanup) - #154233 (Move ui/issues tests to relevant subdirectories)
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Mar 25, 2026
Add `-Zsanitize=kernel-hwaddress` The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS` that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust. One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable. Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it. MCP: rust-lang/compiler-team#975 Tracking issue: rust-lang#154171 cc @rcvalle @maurer @ojeda
rust-bors Bot
pushed a commit
that referenced
this pull request
Mar 25, 2026
Rollup of 5 pull requests Successful merges: - #153049 (Add `-Zsanitize=kernel-hwaddress`) - #154269 (miri recursive validation: only check one layer deep) - #154112 (some `tests/ui/macros` cleanup) - #154131 (begin `tests/ui/structs-enums` cleanup) - #154233 (Move ui/issues tests to relevant subdirectories)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 25, 2026
Add `-Zsanitize=kernel-hwaddress` The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS` that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust. One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable. Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it. MCP: rust-lang/compiler-team#975 Tracking issue: rust-lang#154171 cc @rcvalle @maurer @ojeda
This was referenced Mar 25, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Mar 25, 2026
…uwer Rollup of 22 pull requests Successful merges: - #153049 (Add `-Zsanitize=kernel-hwaddress`) - #153702 (Add macro matcher for `guard` fragment specifier) - #154200 (debuginfo: emit DW_TAG_call_site entries) - #154263 (interpret: when passing an argument fails, point at that argument) - #154269 (miri recursive validation: only check one layer deep) - #154313 (Init `self_decl` with a correct visibility) - #154344 (Update LLVM to 22.1.2) - #154348 (re-enable enzyme/autodiff builds on dist-aarch64-apple) - #154351 (Overhaul `Erasable` impls) - #154363 (delegation: fix zero-args nested delegation ICE) - #154364 (delegation: don't propagate synthetic params, remove lifetime hacks) - #151148 (Add functions to `GrowableBitSet`) - #154090 (Move tests in the statics category) - #154112 (some `tests/ui/macros` cleanup) - #154131 (begin `tests/ui/structs-enums` cleanup) - #154216 (unstably mark `NonNull::with_exposed_provenance` as const) - #154230 (Moved and rename issue-50411 to tests/ui/mir/inliner-double-elaborate) - #154233 (Move ui/issues tests to relevant subdirectories) - #154288 (Fix typo in doc comment for `char::to_titlecase`) - #154355 (delegation: add const type ICE test) - #154358 (install-template.sh: Optimize by using Bourne shell builtins.) - #154360 (fromrangeiter-overflow-checks: accept optional `signext` for argument)
github-actions Bot
pushed a commit
to rust-lang/stdarch
that referenced
this pull request
Mar 26, 2026
Fix minor kasan bugs Fixes a few minor bugs discovered during rust-lang/rust#153049.
github-actions Bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Mar 26, 2026
…uwer Rollup of 22 pull requests Successful merges: - rust-lang/rust#153049 (Add `-Zsanitize=kernel-hwaddress`) - rust-lang/rust#153702 (Add macro matcher for `guard` fragment specifier) - rust-lang/rust#154200 (debuginfo: emit DW_TAG_call_site entries) - rust-lang/rust#154263 (interpret: when passing an argument fails, point at that argument) - rust-lang/rust#154269 (miri recursive validation: only check one layer deep) - rust-lang/rust#154313 (Init `self_decl` with a correct visibility) - rust-lang/rust#154344 (Update LLVM to 22.1.2) - rust-lang/rust#154348 (re-enable enzyme/autodiff builds on dist-aarch64-apple) - rust-lang/rust#154351 (Overhaul `Erasable` impls) - rust-lang/rust#154363 (delegation: fix zero-args nested delegation ICE) - rust-lang/rust#154364 (delegation: don't propagate synthetic params, remove lifetime hacks) - rust-lang/rust#151148 (Add functions to `GrowableBitSet`) - rust-lang/rust#154090 (Move tests in the statics category) - rust-lang/rust#154112 (some `tests/ui/macros` cleanup) - rust-lang/rust#154131 (begin `tests/ui/structs-enums` cleanup) - rust-lang/rust#154216 (unstably mark `NonNull::with_exposed_provenance` as const) - rust-lang/rust#154230 (Moved and rename issue-50411 to tests/ui/mir/inliner-double-elaborate) - rust-lang/rust#154233 (Move ui/issues tests to relevant subdirectories) - rust-lang/rust#154288 (Fix typo in doc comment for `char::to_titlecase`) - rust-lang/rust#154355 (delegation: add const type ICE test) - rust-lang/rust#154358 (install-template.sh: Optimize by using Bourne shell builtins.) - rust-lang/rust#154360 (fromrangeiter-overflow-checks: accept optional `signext` for argument)
intel-lab-lkp
pushed a commit
to intel-lab-lkp/linux
that referenced
this pull request
Mar 26, 2026
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: rust-lang/rust#153049 [1] Signed-off-by: Alice Ryhl <aliceryhl@google.com>
intel-lab-lkp
pushed a commit
to intel-lab-lkp/linux
that referenced
this pull request
Apr 2, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
sync-agent-neo Bot
pushed a commit
to aosp-mirror-neo/kernel_common
that referenced
this pull request
Apr 8, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@google.com Bug: 493254381 Change-Id: Icbe302adf0b8358668760a621570eeba76e10019 Signed-off-by: Alice Ryhl <aliceryhl@google.com>
sync-agent-neo Bot
pushed a commit
to aosp-mirror-neo/kernel_common
that referenced
this pull request
Apr 8, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@google.com Bug: 493254381 Bug: 500480668 Signed-off-by: Alice Ryhl <aliceryhl@google.com> Cherrypick-From: https://android-review.googlesource.com/q/commit:f2435d765f35e62e77a78a115ce53a135e9df010 Merged-In: Icbe302adf0b8358668760a621570eeba76e10019 Change-Id: Icbe302adf0b8358668760a621570eeba76e10019
sync-agent-neo Bot
pushed a commit
to aosp-mirror-neo/kernel_common
that referenced
this pull request
Apr 9, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@google.com Bug: 493254381 Bug: 500416959 Change-Id: Icbe302adf0b8358668760a621570eeba76e10019 Signed-off-by: Alice Ryhl <aliceryhl@google.com> (cherry picked from commit f2435d7)
sync-agent-neo Bot
pushed a commit
to aosp-mirror-neo/kernel_common
that referenced
this pull request
Apr 11, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@google.com Bug: 493254381 Change-Id: Icbe302adf0b8358668760a621570eeba76e10019 Signed-off-by: Alice Ryhl <aliceryhl@google.com>
intel-lab-lkp
pushed a commit
to intel-lab-lkp/linux
that referenced
this pull request
Apr 11, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
ojeda
pushed a commit
to ojeda/linux
that referenced
this pull request
May 26, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260408-kasan-rust-sw-tags-v3-2-e07964d14363@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda
pushed a commit
to Rust-for-Linux/linux
that referenced
this pull request
May 27, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260408-kasan-rust-sw-tags-v3-2-e07964d14363@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
flip1995
pushed a commit
to flip1995/rust-clippy
that referenced
this pull request
Aug 17, 2026
…uwer Rollup of 22 pull requests Successful merges: - rust-lang/rust#153049 (Add `-Zsanitize=kernel-hwaddress`) - rust-lang/rust#153702 (Add macro matcher for `guard` fragment specifier) - rust-lang/rust#154200 (debuginfo: emit DW_TAG_call_site entries) - rust-lang/rust#154263 (interpret: when passing an argument fails, point at that argument) - rust-lang/rust#154269 (miri recursive validation: only check one layer deep) - rust-lang/rust#154313 (Init `self_decl` with a correct visibility) - rust-lang/rust#154344 (Update LLVM to 22.1.2) - rust-lang/rust#154348 (re-enable enzyme/autodiff builds on dist-aarch64-apple) - rust-lang/rust#154351 (Overhaul `Erasable` impls) - rust-lang/rust#154363 (delegation: fix zero-args nested delegation ICE) - rust-lang/rust#154364 (delegation: don't propagate synthetic params, remove lifetime hacks) - rust-lang/rust#151148 (Add functions to `GrowableBitSet`) - rust-lang/rust#154090 (Move tests in the statics category) - rust-lang/rust#154112 (some `tests/ui/macros` cleanup) - rust-lang/rust#154131 (begin `tests/ui/structs-enums` cleanup) - rust-lang/rust#154216 (unstably mark `NonNull::with_exposed_provenance` as const) - rust-lang/rust#154230 (Moved and rename issue-50411 to tests/ui/mir/inliner-double-elaborate) - rust-lang/rust#154233 (Move ui/issues tests to relevant subdirectories) - rust-lang/rust#154288 (Fix typo in doc comment for `char::to_titlecase`) - rust-lang/rust#154355 (delegation: add const type ICE test) - rust-lang/rust#154358 (install-template.sh: Optimize by using Bourne shell builtins.) - rust-lang/rust#154360 (fromrangeiter-overflow-checks: accept optional `signext` for argument)
ditvelo
pushed a commit
to ditvelo/android_kernel_common_oppo_sm8845
that referenced
this pull request
Sep 8, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@google.com Bug: 493254381 Bug: 500480668 Signed-off-by: Alice Ryhl <aliceryhl@google.com> Cherrypick-From: https://android-review.googlesource.com/q/commit:f2435d765f35e62e77a78a115ce53a135e9df010 Merged-In: Icbe302adf0b8358668760a621570eeba76e10019 Change-Id: Icbe302adf0b8358668760a621570eeba76e10019
Portisch
pushed a commit
to Portisch/linux-amlogic
that referenced
this pull request
Oct 13, 2026
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: rust-lang/rust#153049 [1] Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331-kasan-rust-sw-tags-v2-1-f6765e3e1a2f@google.com Bug: 493254381 Bug: 500416959 Change-Id: Icbe302adf0b8358668760a621570eeba76e10019 Signed-off-by: Alice Ryhl <aliceryhl@google.com> (cherry picked from commit f2435d765f35e62e77a78a115ce53a135e9df010)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
View all comments
The Linux kernel has a config option called
CONFIG_KASAN_SW_TAGSthat enables-fsanitize=kernel-hwaddress. This is not supported by Rust.One slightly awkward detail is that
#[sanitize(address = "off")]applies to both-Zsanitize=addressand-Zsanitize=kernel-address. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable.Note that
#[sanitize(kernel_hwaddress = "off")]could be supported as an annotation on statics, but since it's also missing for#[sanitize(hwaddress = "off")], I did not add it.MCP: rust-lang/compiler-team#975
Tracking issue: #154171
cc @rcvalle @maurer @ojeda