Fix use-after-free in Runtime::DestroyAgents() cleanup ordering#3240
Open
shwetagkhatri wants to merge 2 commits intodevelopfrom
Open
Fix use-after-free in Runtime::DestroyAgents() cleanup ordering#3240shwetagkhatri wants to merge 2 commits intodevelopfrom
shwetagkhatri wants to merge 2 commits intodevelopfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a use-after-free bug in the ROCm runtime's cleanup sequence by reordering operations in Runtime::DestroyAgents(). The fix ensures system memory regions are cleared before agents are destroyed, preventing potential corruption when agent destructors access region memory.
Changes:
- Moved clearing of
system_regions_fine_andsystem_regions_coarse_to occur before agent destruction instead of after - Added explanatory comment describing the rationale for the ordering change
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cfreeamd
approved these changes
Feb 12, 2026
Clear system memory regions before destroying agents to prevent use-after-free corruption when agent destructors access region memory.
Keep a single hsa_shut_down() in CommonCleanUp because a second shutdown trips ASAN’s device allocator after unload
1979a3a to
833dd34
Compare
radhaksri
added a commit
to ROCm/TheRock
that referenced
this pull request
Feb 13, 2026
Cherry-picked commits from ROCm/rocm-systems#3240: - Fix use-after-free in Runtime::DestroyAgents() cleanup ordering - rocrtst: Avoid double shutdown under ASAN
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.
Clear system memory regions before destroying agents to prevent use-after-free corruption when agent destructors access region memory.
Motivation
Technical Details
JIRA ID
Test Plan
Test Result
Submission Checklist