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

Fix use-after-free on panic during ArcWake::wake_by_ref #1797

Merged
merged 1 commit into from
Aug 15, 2019

Conversation

stbuehler
Copy link
Contributor

Wrap temporary Arc<>s in ManuallyDrop early instead of calling forget() later: that way even during unwinding for panics it doesn't drop the refcount it doesn't actually own.

Also it means wake_by_ref doesn't need an unwind section anymore.

Same thing in increase_refcount (although Arc::clone should only abort, not unwind).

@cramertj
Copy link
Member

Nice! Would you mind adding a test for this?

Wrap temporary `Arc<>`s in `ManuallyDrop` early instead of calling
`forget()` later: that way even during unwinding for panics it doesn't
drop the refcount it doesn't actually own.

Also it means `wake_by_ref` doesn't need an unwind section anymore.

Same thing in `increase_refcount` (although `Arc::clone` should only abort,
not unwind).
@stbuehler
Copy link
Contributor Author

Added a test (if you prefer it in a separate commit before/after the fix I can split it of course).

The test fails for me without the fix applied:

error: process didn't exit successfully: `[...]/futures/target/debug/deps/arc_wake-e1af0914f1200023` (signal: 11, SIGSEGV: invalid memory reference)

@cramertj
Copy link
Member

Wonderful, thank you!

@cramertj cramertj merged commit f2b6b87 into rust-lang:master Aug 15, 2019
@stbuehler stbuehler deleted the manualdrop branch August 15, 2019 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants