Repository navigation
[c10d] Fix use-after-free in FlightRecorder::dump_entries - #192232
Closed
tushar00jain wants to merge 4 commits into
Closed
tushar00jain wants to merge 4 commits into
tushar00jain wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192232
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 28c3572 with merge base aafcd51 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 5, 2026
Closed
Closed
Closed
Skylion007
approved these changes
Aug 5, 2026
Contributor
Author
|
@pytorchbot merge |
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
ankitbhrdwj
pushed a commit
to ankitbhrdwj/pytorch
that referenced
this pull request
Aug 12, 2026
…2232) FlightRecorder::Entry holds *borrowed* raw EventType pointers, owned by whoever created the work. dump_entries copied the matching entries out under mutex_ and then ran the update_state loop -- which calls start_->query() / end_->query() -- on those copies after releasing the lock. Any thread that completed a work and freed its events in that window left the dumping thread querying freed memory. The window is reachable from any concurrent _dump_fr_trace / _dump_nccl_trace. retire_id is the reason the lock matters: it is what clears an entry's event pointers before the owner frees the events, and it does so under mutex_. Copying the pointers out and dereferencing them outside that mutex defeats it. The fix moves the update_state + null-out loop inside the existing mutex_ scope. This adds no new blocking: retire_id already called update_state under the lock, and query() is non-blocking. The genuinely blocking call, getDurationFromEvent, still runs with the lock released. This is a pre-existing defect rather than one introduced by the flight-recorder work stacked on top of it, but that work makes it far easier to hit, because it gives the recorder a second concurrent owner of entry events. Test Plan: Verified with the rest of the flight-recorder stack applied; NCCLTraceTest is the suite that covers concurrent dump paths, buffer wraparound and reset: ``` python test/distributed/test_c10d_nccl.py NCCLTraceTest -v ``` ``` Ran 61 tests in 476.792s OK ``` Authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#192232 Approved by: https://github.com/Skylion007, https://github.com/kapilsh, https://github.com/d4l3k
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.
Stack from ghstack (oldest at bottom):
FlightRecorder::Entry holds borrowed raw EventType pointers, owned by whoever
created the work. dump_entries copied the matching entries out under mutex_ and
then ran the update_state loop -- which calls start_->query() / end_->query() --
on those copies after releasing the lock. Any thread that completed a work and
freed its events in that window left the dumping thread querying freed memory.
The window is reachable from any concurrent _dump_fr_trace / _dump_nccl_trace.
retire_id is the reason the lock matters: it is what clears an entry's event
pointers before the owner frees the events, and it does so under mutex_. Copying
the pointers out and dereferencing them outside that mutex defeats it.
The fix moves the update_state + null-out loop inside the existing mutex_ scope.
This adds no new blocking: retire_id already called update_state under the lock,
and query() is non-blocking. The genuinely blocking call, getDurationFromEvent,
still runs with the lock released.
This is a pre-existing defect rather than one introduced by the flight-recorder
work stacked on top of it, but that work makes it far easier to hit, because it
gives the recorder a second concurrent owner of entry events.
Test Plan:
Verified with the rest of the flight-recorder stack applied; NCCLTraceTest is
the suite that covers concurrent dump paths, buffer wraparound and reset:
Authored with the assistance of an AI coding agent.