Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling ASan instrumentation for globals #127483

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

BertalanD
Copy link
Contributor

AddressSanitizer adds instrumentation to global variables unless the no_sanitize_address attribute is set on them.

This commit extends the existing #[no_sanitize(address)] attribute to set this; previously it only had the desired effect on functions.

(cc #39699)

@rustbot
Copy link
Collaborator

rustbot commented Jul 8, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 8, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 8, 2024

Some changes occurred in tests/codegen/sanitizer

cc @rust-lang/project-exploit-mitigations, @rcvalle

@rust-log-analyzer

This comment has been minimized.

@rcvalle
Copy link
Member

rcvalle commented Jul 9, 2024

LGTM (@cuviper FYI). We'll want this for #123617. Thank you for your time and for working on this, @BertalanD! Much appreciated.

@rcvalle
Copy link
Member

rcvalle commented Jul 9, 2024

@BertalanD do you know if there is anything else possibly missing instrumentation before #123617?

@BertalanD
Copy link
Contributor Author

BertalanD commented Jul 9, 2024

Thank you for reviewing; I pushed up the suggested style change.

I haven't looked into missing instrumentation, so I can't help with that. But what might be relevant for stabilization is that this came up in the context of a Chromium issue where the added ASan annotation on #[small_ctor::ctor] items resulted in link-time crashes and run-time failures on Apple platforms.

@rcvalle
Copy link
Member

rcvalle commented Jul 9, 2024

Thank you for the information and for sending it out, @BertalanD! I'll take a look.

@BertalanD
Copy link
Contributor Author

BertalanD commented Jul 9, 2024

@rcvalle

ctor and linkme are two other crates that will definitely be impacted by ASan annotation on global variables (alongside small_ctor).

The operation of all three basically boils down to creating a special section in the output file that's an array of pointers, by creating static variables annotated with #[link_section]. The ASan instrumentation pads these to 32 bytes, filling the rest with zeros. So the code that traverses the array will either stop processing them when encountering the zeros (this is what dyld does for me on macOS 15), or crash with a null deref in the worst case.

@bors
Copy link
Contributor

bors commented Jul 17, 2024

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

@BertalanD BertalanD force-pushed the no_sanitize-global-var branch 2 times, most recently from 670c03e to 9447dc7 Compare September 17, 2024 07:41
@rust-log-analyzer

This comment has been minimized.

@Dylan-DPC Dylan-DPC 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 Oct 29, 2024
@Dylan-DPC
Copy link
Member

@BertalanD if you can address the CI failure we can push this forward :) thanks

AddressSanitizer adds instrumentation to global variables unless the
[`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes)
attribute is set on them.

This commit extends the existing `#[no_sanitize(address)]` attribute to
set this; previously it only had the desired effect on functions.
@Dylan-DPC Dylan-DPC added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 5, 2024
@rcvalle
Copy link
Member

rcvalle commented Nov 23, 2024

@bors r+

@rcvalle rcvalle self-assigned this Nov 23, 2024
@rcvalle
Copy link
Member

rcvalle commented Nov 23, 2024

@bors ping

@cuviper cuviper closed this Nov 23, 2024
@cuviper cuviper reopened this Nov 23, 2024
@cuviper
Copy link
Member

cuviper commented Nov 23, 2024

@bors r=rcvalle

@bors
Copy link
Contributor

bors commented Nov 23, 2024

📌 Commit 204b228 has been approved by rcvalle

It is now in the queue for this repository.

@bors bors 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 Nov 23, 2024
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Nov 23, 2024
…r=rcvalle

Allow disabling ASan instrumentation for globals

AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them.

This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.

(cc rust-lang#39699)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 23, 2024
…r=rcvalle

Allow disabling ASan instrumentation for globals

AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them.

This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.

(cc rust-lang#39699)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#127483 (Allow disabling ASan instrumentation for globals)
 - rust-lang#131505 (use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin)
 - rust-lang#132949 (Add specific diagnostic for using macro_rules macro as attribute/derive)
 - rust-lang#133247 (Reduce integer `Display` implementation size)
 - rust-lang#133286 (Re-delay a resolve `bug` related to `Self`-ctor in patterns)
 - rust-lang#133332 (Mark `<[T; N]>::as_mut_slice` with the `const` specifier.)
 - rust-lang#133366 (Remove unnecessary bool from `ExpectedFound::new`)

Failed merges:

 - rust-lang#131859 (Update TRPL to add new Chapter 17: Async and Await)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#127483 (Allow disabling ASan instrumentation for globals)
 - rust-lang#131505 (use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin)
 - rust-lang#132949 (Add specific diagnostic for using macro_rules macro as attribute/derive)
 - rust-lang#133286 (Re-delay a resolve `bug` related to `Self`-ctor in patterns)
 - rust-lang#133332 (Mark `<[T; N]>::as_mut_slice` with the `const` specifier.)
 - rust-lang#133366 (Remove unnecessary bool from `ExpectedFound::new`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c6d3625 into rust-lang:master Nov 23, 2024
12 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Nov 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2024
Rollup merge of rust-lang#127483 - BertalanD:no_sanitize-global-var, r=rcvalle

Allow disabling ASan instrumentation for globals

AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them.

This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.

(cc rust-lang#39699)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant 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.

8 participants