Add -Zsanitize=kernel-hwaddress#153049
Conversation
1191bc5 to
07c2a2a
Compare
This comment has been minimized.
This comment has been minimized.
07c2a2a to
9508e21
Compare
This comment has been minimized.
This comment has been minimized.
9508e21 to
c7a338e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // 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); | ||
| } |
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.
|
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 |
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Add `-Zsanitize=kernel-hwaddress` try-job: test-various try-job: aarch64-gnu
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in src/doc/unstable-book/src/compiler-flags/sanitizer.md cc @rust-lang/project-exploit-mitigations, @rcvalle
These commits modify compiler targets. |
|
@rustbot ready |
|
Thanks! @bors r+ |
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
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)
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
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)
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
…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)
Fix minor kasan bugs Fixes a few minor bugs discovered during rust-lang/rust#153049.
…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)
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>
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