Skip to content

multi: handle pause in multi socket callback#21748

Closed
bagder wants to merge 2 commits into
masterfrom
bagder/multi-cb
Closed

multi: handle pause in multi socket callback#21748
bagder wants to merge 2 commits into
masterfrom
bagder/multi-cb

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented May 26, 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

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.

@bagder bagder marked this pull request as ready for review May 26, 2026 08:02
@bagder bagder requested a review from Copilot May 26, 2026 08:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 magic field to struct mev_sh_entry, set on creation and cleared on destruction.
  • Add DEBUGASSERT checks to validate mev_sh_entry pointers 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.

Comment thread lib/multi_ev.h Outdated
Comment thread lib/multi_ev.c
bagder added 2 commits May 26, 2026 10:32
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
@bagder bagder force-pushed the bagder/multi-cb branch from fd0abac to 7b2730f Compare May 26, 2026 08:33
@bagder bagder closed this in 5ab34cb May 26, 2026
@bagder bagder deleted the bagder/multi-cb branch May 26, 2026 09:12
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants