hi-mlx expert_pool: close fd leaks, fix mmap read overflow - #145
Closed
davidrhodus wants to merge 1 commit into
Closed
hi-mlx expert_pool: close fd leaks, fix mmap read overflow#145davidrhodus wants to merge 1 commit into
davidrhodus wants to merge 1 commit into
Conversation
- MmapShard leaked both file descriptors (std::mem::forget on the File and the F_NOCACHE direct fd) and never closed the mmap fd on Drop, so each opened shard permanently consumed two fds — a slow leak across repeated model loads. Both fds are now owned via into_raw_fd and closed exactly once in Drop after munmap, removing the leak and the confused stale comment. - MmapShard::read computed end = start + len without a checked_add, so a huge offset/len pair could wrap and pass the bounds check, reading out of bounds. Now uses checked_add and rejects overflow. - models.rs: prefix the now-unused pad_attention_bias param (cache bound is derived from kv_len - l instead) to silence the warning. expert_pool 9/9 tests pass with --features mlx; GPU backend tests are environmentally blocked here (sandbox denies mlx.metallib caching) and fail identically on HEAD — no regressions. cargo check --workspace clean
Contributor
Author
|
These changes are already on |
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.
Summary
Two soundness/resource fixes in
crates/hi-mlx/src/expert_pool.rs(MmapShard):File-descriptor leak.
MmapShard::openleaked both fds viastd::mem::forget— theFilebacking the mmap and the F_NOCACHE direct fd — andDropnever closed the mmap fd. Each opened shard permanently consumed two descriptors, a slow leak across repeated model loads. Both fds are now owned viainto_raw_fdand closed exactly once inDropaftermunmap(no leak, no double-close), and the confused stale comment is removed.Out-of-bounds read via integer overflow.
MmapShard::readcomputedend = start + lenwithout a checked add, so a huge offset/length pair could wrap past theend > self.lenbounds check and read out of bounds. Now useschecked_addand rejects overflow.Also prefixes the now-unused
pad_attention_biasoffsetparam inmodels.rs(the cache bound is correctly derived fromkv_len - lper the in-loop rationale) to silence the warning.Verification
cargo test -p hi-mlx --features mlx --lib expert_pool: 9/9 pass.mlx.metallib) and fails identically on the base — no regressions from these changes.cargo check --workspace: clean.