Skip to content

Fix observable intermediate state in thread::add_spawn_hook#159956

Open
maxdexh wants to merge 2 commits into
rust-lang:mainfrom
maxdexh:fix-thread-spawn-hook-159923
Open

Fix observable intermediate state in thread::add_spawn_hook#159956
maxdexh wants to merge 2 commits into
rust-lang:mainfrom
maxdexh:fix-thread-spawn-hook-159923

Conversation

@maxdexh

@maxdexh maxdexh commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #159923.

Ensures the intermediate state of there being no hooks in add_spawn_hooks is not observable by allocating the new head node before taking the current hook list.

Also added a note to the docs of add_spawn_hook that hooks are not guaranteed to run and cannot be relied upon for soundness, as there are multiple ways to prevent all/some hooks from running.

@rustbot rustbot added 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 26, 2026
@rustbot

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 15 candidates

@maxdexh

maxdexh commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author
  • Owners of files modified in this PR: compiler

This doesn't touch the compiler?

@folkertdev

Copy link
Copy Markdown
Contributor

I guess all of the compiler is compiler? anyhow, I think you can also explicitly

r? libs

@maxdexh

maxdexh commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks ^^
It's probably because I had to add the test in ui/std (at least it didn't work anywhere else, idk if I did something wrong), since it uses a custom global allocator.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f80e5c1 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot 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 Jul 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 27, 2026
…23, r=Mark-Simulacrum

Fix observable intermediate state in `thread::add_spawn_hook`

Fixes rust-lang#159923.

Ensures the intermediate state of there being no hooks in `add_spawn_hooks` is not observable by allocating the new head node before taking the current hook list.

Also added a note to the docs of `add_spawn_hook` that hooks are not guaranteed to run and cannot be relied upon for soundness, as there are multiple ways to prevent all/some hooks from running.
rust-bors Bot pushed a commit that referenced this pull request Jul 27, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - #159554 (feat: Update method signature of int_from_ascii)
 - #159637 (Some place analysis tweaks)
 - #159961 (sanitize_standard_fds: Miri supports poll now)
 - #159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - #159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - #159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - #159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
rust-bors Bot pushed a commit that referenced this pull request Jul 27, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - #159554 (feat: Update method signature of int_from_ascii)
 - #159637 (Some place analysis tweaks)
 - #159961 (sanitize_standard_fds: Miri supports poll now)
 - #159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - #159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - #159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - #159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 27, 2026
…23, r=Mark-Simulacrum

Fix observable intermediate state in `thread::add_spawn_hook`

Fixes rust-lang#159923.

Ensures the intermediate state of there being no hooks in `add_spawn_hooks` is not observable by allocating the new head node before taking the current hook list.

Also added a note to the docs of `add_spawn_hook` that hooks are not guaranteed to run and cannot be relied upon for soundness, as there are multiple ways to prevent all/some hooks from running.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 27, 2026
…23, r=Mark-Simulacrum

Fix observable intermediate state in `thread::add_spawn_hook`

Fixes rust-lang#159923.

Ensures the intermediate state of there being no hooks in `add_spawn_hooks` is not observable by allocating the new head node before taking the current hook list.

Also added a note to the docs of `add_spawn_hook` that hooks are not guaranteed to run and cannot be relied upon for soundness, as there are multiple ways to prevent all/some hooks from running.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread spawn hooks can be removed using unwinding handle_alloc_error

4 participants