Skip to content

Fix use-after-free in Runtime::DestroyAgents() cleanup ordering#3240

Open
shwetagkhatri wants to merge 2 commits intodevelopfrom
users/shwetak/fix-destroy-agents-use-after-free
Open

Fix use-after-free in Runtime::DestroyAgents() cleanup ordering#3240
shwetagkhatri wants to merge 2 commits intodevelopfrom
users/shwetak/fix-destroy-agents-use-after-free

Conversation

@shwetagkhatri
Copy link
Contributor

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

Copy link
Contributor

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 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_ and system_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.

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
@shwetagkhatri shwetagkhatri force-pushed the users/shwetak/fix-destroy-agents-use-after-free branch from 1979a3a to 833dd34 Compare February 12, 2026 21:53
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants