Skip to content

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

Merged
JeniferC99 merged 2 commits into
developfrom
users/shwetak/fix-destroy-agents-use-after-free
Feb 26, 2026
Merged

Fix use-after-free in Runtime::DestroyAgents() cleanup ordering#3240
JeniferC99 merged 2 commits into
developfrom
users/shwetak/fix-destroy-agents-use-after-free

Conversation

@shwetagkhatri
Copy link
Copy Markdown
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
Copy Markdown
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.

@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
Comment thread projects/rocr-runtime/rocrtst/common/base_rocr_utils.cc
Comment thread projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp Outdated
@shwetagkhatri shwetagkhatri force-pushed the users/shwetak/fix-destroy-agents-use-after-free branch from 833dd34 to 1d87969 Compare February 19, 2026 23:38
…Runtime::Unload

Clear system memory regions before destroying agents to prevent
use-after-free corruption when agent destructors access region memory.
@shwetagkhatri shwetagkhatri force-pushed the users/shwetak/fix-destroy-agents-use-after-free branch from 4be9b90 to 7a9237d Compare February 24, 2026 03:23
@JeniferC99 JeniferC99 merged commit 0b16567 into develop Feb 26, 2026
20 of 21 checks passed
@JeniferC99 JeniferC99 deleted the users/shwetak/fix-destroy-agents-use-after-free branch February 26, 2026 01:55
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.

6 participants