std::sys::sgx::tls: fix TLS destructor pointer provenance - #161960
Open
phlip9 wants to merge 1 commit into
Open
Conversation
Storing the TLS entry destructor as an `AtomicUsize` loses the pointer provenance and makes miri cry :'(
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project has assigned @clarfonthey (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
Wow, i recently changed something surrounding this code and i just assumed this was an @rustbot label T-opsem |
Contributor
|
Seems reasonable to me. @bors try jobs=dist-various-2 (since this job checks x86_64-fortanix-unknown-sgx) |
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 29, 2026
…try> std::sys::sgx::tls: fix TLS destructor pointer provenance try-job: dist-various-2
Contributor
Contributor
|
@bors r+ rollup Thank you! |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 29, 2026
…enance, r=clarfonthey std::sys::sgx::tls: fix TLS destructor pointer provenance Storing the TLS entry destructor as an `AtomicUsize` loses the pointer provenance and makes miri cry :'( Instead, store an `AtomicPtr<()>`. I also find the SAFETY proof more convincing when the transmute from `*mut ()` to `Option<unsafe extern "C" fn(*mut u8)>` is exactly mirrored. https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=c6da201f269c5f3115039177a43bcdd4 ``` Compiling playground v0.0.1 (/playground) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.70s Running `/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/playground` error: Undefined Behavior: pointer not dereferenceable: pointer must point to some allocation, but got 0x26b51[noalloc] which is a dangling pointer (it has no provenance) --> src/tls-bad.rs:73:30 | 73 | unsafe { dtor(value) } | ^^^^^^^^^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: stack backtrace: 0: <tls::ActiveTls<'_> as std::ops::Drop>::drop at src/tls-bad.rs:73:30: 73:41 1: std::ptr::drop_glue::<tls::ActiveTls<'_>> - shim(Some(tls::ActiveTls<'_>)) at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:848:1: 850:25 2: main at src/main.rs:50:1: 50:2 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace error: aborting due to 1 previous error ```
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.
Storing the TLS entry destructor as an
AtomicUsizeloses the pointer provenance and makes miri cry :'(Instead, store an
AtomicPtr<()>. I also find the SAFETY proof more convincing when the transmute from*mut ()toOption<unsafe extern "C" fn(*mut u8)>is exactly mirrored.https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=c6da201f269c5f3115039177a43bcdd4