[TENT] Fix Memory Management Issues#1486
Conversation
Summary of ChangesHello @alogfans, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves critical memory management issues within the TENT (Transfer Engine) component. It specifically addresses a potential use-after-free scenario in the slab memory pool during program exit and rectifies resource leaks in the MNNVL transport mechanism by ensuring proper release of CUDA memory, allocation handles, and file descriptors. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to resolve a use-after-free bug in the Slab memory pool and resource leaks in the MnnvlTransport. While addressing these, it unfortunately introduces new Use-After-Free vulnerabilities due to race conditions and stale thread-local caches, particularly in the destruction logic for SlabBase and the uninstallation process for MnnvlTransport, which do not safely handle concurrent access. Furthermore, the new resource handling logic in relocateSharedMemoryAddress can lead to leaks on certain error paths.
mooncake-transfer-engine/tent/src/transport/mnnvl/mnnvl_transport.cpp
Outdated
Show resolved
Hide resolved
| cuMemUnmap((CUdeviceptr)entry.mnnvl_addr, entry.length); | ||
| } | ||
|
|
||
| // Release the address reservation | ||
| if (entry.mnnvl_addr) { | ||
| cuMemAddressFree((CUdeviceptr)entry.mnnvl_addr, entry.length); | ||
| } |
There was a problem hiding this comment.
This section introduces a Use-After-Free vulnerability. While the memory unmapping and address freeing in uninstall() correctly prevent resource leaks, they do not account for other threads that may have cached these addresses in their thread_local tl_relocate_map. When uninstall() unmaps the memory, any thread using a cached address from its local tl_relocate_map will encounter a Use-After-Free or illegal memory access. The thread_local caches must be invalidated or cleared when the transport is uninstalled. For better readability, the separate checks for entry.mnnvl_addr could also be combined.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
Fixed two critical memory management issues in TENT (Transfer Engine):
Type of Change
How Has This Been Tested?
Checklist
./scripts/code_format.shbefore submitting.