Skip to content

fix(fast_io): bounds-check io_uring recycle_buffer in release - #3631

Merged
oferchen merged 1 commit into
masterfrom
fix/io-uring-recycle-buffer-bounds-check
May 5, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/io-uring-recycle-buffer-bounds-check

Conversation

@oferchen

@oferchen oferchen commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces the release-mode no-op debug_assert! in BufferRing::recycle_buffer with a runtime bounds check that returns a new BufferRingError::BufferIdOutOfRange (mapped to io::ErrorKind::InvalidInput) before any state mutation.
  • Without this check, a stray buf_id >= ring_size would advance the ring tail past valid entries and write a bogus IoUringBuf into kernel-shared mmap memory, corrupting subsequent provided-buffer selection. The check refuses the recycle instead so we never touch the ring on a bad ID.
  • Updates the non-Linux io_uring_stub::BufferRing::recycle_buffer to match the new Result signature so cross-platform callers can use ? without cfg-gating.

Refs #2042

Test plan

  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl. Local cargo not run per project policy.

The previous `debug_assert!` on `buf_id < ring_size` in
`BufferRing::recycle_buffer` was a no-op in release builds, so a
caller passing a stray ID could advance the ring tail past the
configured range and write a bogus `IoUringBuf` into kernel-shared
memory, corrupting subsequent buffer selection.

Replace the debug assertion with a runtime bounds check that returns
a new `BufferRingError::BufferIdOutOfRange` (mapped to
`io::ErrorKind::InvalidInput`) before any state mutation, so a bad
`buf_id` is refused without touching the ring tail. Update the
non-Linux stub to match the new `Result` signature and cover the new
behaviour with tests.

Refs #2042
@github-actions github-actions Bot added the bug Something isn't working label May 5, 2026
@oferchen
oferchen merged commit 4586481 into master May 5, 2026
40 checks passed
@oferchen
oferchen deleted the fix/io-uring-recycle-buffer-bounds-check branch May 5, 2026 09:41
oferchen added a commit that referenced this pull request May 18, 2026
The previous `debug_assert!` on `buf_id < ring_size` in
`BufferRing::recycle_buffer` was a no-op in release builds, so a
caller passing a stray ID could advance the ring tail past the
configured range and write a bogus `IoUringBuf` into kernel-shared
memory, corrupting subsequent buffer selection.

Replace the debug assertion with a runtime bounds check that returns
a new `BufferRingError::BufferIdOutOfRange` (mapped to
`io::ErrorKind::InvalidInput`) before any state mutation, so a bad
`buf_id` is refused without touching the ring tail. Update the
non-Linux stub to match the new `Result` signature and cover the new
behaviour with tests.

Refs #2042
oferchen added a commit that referenced this pull request Aug 24, 2026
The previous `debug_assert!` on `buf_id < ring_size` in
`BufferRing::recycle_buffer` was a no-op in release builds, so a
caller passing a stray ID could advance the ring tail past the
configured range and write a bogus `IoUringBuf` into kernel-shared
memory, corrupting subsequent buffer selection.

Replace the debug assertion with a runtime bounds check that returns
a new `BufferRingError::BufferIdOutOfRange` (mapped to
`io::ErrorKind::InvalidInput`) before any state mutation, so a bad
`buf_id` is refused without touching the ring tail. Update the
non-Linux stub to match the new `Result` signature and cover the new
behaviour with tests.

Refs #2042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant