Skip to content

Add MemTagSanitizer Support - #91675

Merged
bors merged 1 commit into
rust-lang:masterfrom
ivanloz:memtagsan
Feb 19, 2022
Merged

Add MemTagSanitizer Support#91675
bors merged 1 commit into
rust-lang:masterfrom
ivanloz:memtagsan

Conversation

@ivanloz

Copy link
Copy Markdown
Contributor

Add support for the LLVM MemTagSanitizer.

On hardware which supports it (see caveats below), the MemTagSanitizer can catch bugs similar to AddressSanitizer and HardwareAddressSanitizer, but with lower overhead.

On a tag mismatch, a SIGSEGV is signaled with code SEGV_MTESERR / SEGV_MTEAERR.

Usage

-Zsanitizer=memtag -C target-feature="+mte"

Comments/Caveats

  • MemTagSanitizer is only supported on AArch64 targets with hardware support
  • Requires -C target-feature="+mte"
  • LLVM MemTagSanitizer currently only performs stack tagging.

TODO

  • Tests
  • Example

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive

Copy link
Copy Markdown
Contributor

⚠️Warning⚠️

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 8, 2021
@rust-log-analyzer

This comment has been minimized.

@apirainoapiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 9, 2021
@ivanloz
ivanloz marked this pull request as draft December 9, 2021 14:45
Comment threadcompiler/rustc_codegen_llvm/src/llvm/ffi.rs Outdated
@ivanloz
ivanlozforce-pushed the memtagsan branch 2 times, most recently from 77bd3d1 to 9b15ee4CompareDecember 9, 2021 21:02
@ivanloz

Copy link
Copy Markdown
ContributorAuthor

Added a basic test which checks that the attribute is being emitted as expected.

@ivanloz
ivanloz marked this pull request as ready for review December 9, 2021 21:05

@davidtwcodavidtwco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me but it's not an area that I'm familiar with.

@davidtwco

Copy link
Copy Markdown
Member

r? @nagisa

@tmiasko

Copy link
Copy Markdown
Contributor

MemTagSanitizer requires hardware support and the mte target feature.

Could we diagnose the attempt to use the sanitizer without mte target feature? This seems like the first issue one would generally encounter when trying to use the sanitizer.

FWIW the implementation looks good to me.

@ivanloz

Copy link
Copy Markdown
ContributorAuthor

Tested passing the sanitizer without the mte target feature, and LLVM throws out a pretty difficult to understand error.

So I've gone ahead and added a check such that rustc errors out if the sanitizer is used without the target feature and emits a useful error message indicating the mte target feature is required.

Comment threadcompiler/rustc_session/src/session.rs Outdated
Comment threadsrc/tools/compiletest/src/header.rs Outdated
Comment threadsrc/test/codegen/sanitizer_memtag_attr_check.rs Outdated
@nagisanagisa added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 27, 2021
@JohnCSimon

Copy link
Copy Markdown

Ping from triage:
@ivanloz can you please address the comments from @nagisa?

@ivanloz

Copy link
Copy Markdown
ContributorAuthor

Apologies and thanks for your patience, this has been on my radar. I expect to have time to address the comments this week.

Comment threadcompiler/rustc_codegen_llvm/src/attributes.rs Outdated
Comment threadsrc/tools/compiletest/src/header.rs Outdated
@nagisa

Copy link
Copy Markdown
Member

r=me with or without the nit fixed.

@bors

bors commented Feb 13, 2022

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #93670) made this pull request unmergeable. Please resolve the merge conflicts.

@ivanloz

Copy link
Copy Markdown
ContributorAuthor

Merge conflicts should be resolved now.

@nagisa

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Feb 15, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit da23682322ec6183f6968068ac2a99565c60abd8 has been approved by nagisa

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 15, 2022
@bors

bors commented Feb 16, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit da23682322ec6183f6968068ac2a99565c60abd8 with merge a08fcc4c75532ca5b4a508d561c9fe753e31333d...

@bors

bors commented Feb 16, 2022

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@borsbors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 16, 2022
@rust-log-analyzer

This comment has been minimized.

Adds support for the LLVM MemTagSanitizer.
@ivanloz

Copy link
Copy Markdown
ContributorAuthor

I removed the quotes from the test's 'target-features' arg -- seems like that may have been causing the testing infrastructure to fail.

@nagisa

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Feb 16, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 568aeda has been approved by nagisa

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 16, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 19, 2022
…askrgr
Rollup of 10 pull requests
Successful merges:
- rust-lang#89892 (Suggest `impl Trait` return type when incorrectly using a generic return type)
- rust-lang#91675 (Add MemTagSanitizer Support)
- rust-lang#92806 (Add more information to `impl Trait` error)
- rust-lang#93497 (Pass `--test` flag through rustdoc to rustc so `#[test]` functions can be scraped)
- rust-lang#93814 (mips64-openwrt-linux-musl: correct soft-foat)
- rust-lang#93847 (kmc-solid: Use the filesystem thread-safety wrapper)
- rust-lang#93877 (asm: Allow the use of r8-r14 as clobbers on Thumb1)
- rust-lang#93892 (Only mark projection as ambiguous if GAT substs are constrained)
- rust-lang#93915 (Implement --check-cfg option (RFC 3013), take 2)
- rust-lang#93953 (Add the `known-bug` test directive, use it, and do some cleanup)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 0bb72a2 into rust-lang:masterFeb 19, 2022
@rustbotrustbot added this to the 1.60.0 milestone Feb 19, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@ivanloz@rust-highfive@rust-log-analyzer@davidtwco@tmiasko@JohnCSimon@nagisa@bors@apiraino@rustbot