multi: handle pause in multi socket callback#21748
Closed
bagder wants to merge 2 commits into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the multi event socket-hash bookkeeping against re-entrancy caused by curl_easy_pause() being called from within the multi socket callback, which can lead to the mev_sh_entry being removed while still in use. It also adds a debug-only “magic” marker to help detect invalid/stale mev_sh_entry pointers during development.
Changes:
- Add a debug-only
magicfield tostruct mev_sh_entry, set on creation and cleared on destruction. - Add
DEBUGASSERTchecks to validatemev_sh_entrypointers in debug builds. - Re-fetch the socket-hash entry after invoking the socket callback to avoid use-after-free when callbacks re-enter multi event assessment.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/multi_ev.h | Adds SH_ENTRY_MAGIC macro used for debug pointer validation. |
| lib/multi_ev.c | Adds debug magic field + asserts; re-fetches socket-hash entry after callback to avoid UAF on re-entrancy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The mev_sh_entry object might be removed if curl_easy_pause() is called from within the socket callback. Introduced a 'magic' struct field to to 'mev_sh_entry' to make it easier to programmatically detect/assert if the pointer is bad - in debug builds. Reported-by: Joshua Rogers
outcast36
pushed a commit
to greearb/curl
that referenced
this pull request
Jun 3, 2026
The mev_sh_entry object might be removed if curl_easy_pause() is called from within the socket callback. Introduced a 'magic' struct field to to 'mev_sh_entry' to make it easier to programmatically detect/assert if the pointer is bad - in debug builds. Reported-by: Joshua Rogers Closes curl#21748
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.
The mev_sh_entry object might be removed if curl_easy_pause() is called from within the socket callback.
Introduced a 'magic' struct field to to 'mev_sh_entry' to make it easier to programmatically detect/assert if the pointer is bad - in debug builds.
Reported-by: Joshua Rogers
This is #21716 but without the test case. The test case is not portable enough and is tricky to make torture friendly because of the timeout etc.