Skip to content

Fix missing per-entry clamp in IoUringBufferRing.useBuffer - #17568

Merged
normanmaurer merged 1 commit into
4.2from
io-uring-buffer-ring-fix-6939f216
Sep 21, 2026
Merged

normanmaurer merged 1 commit into
4.2from
io-uring-buffer-ring-fix-6939f216

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

When IORING_RECVSEND_BUNDLE is enabled, a single completion can report
a byte count spanning multiple buffer-ring entries. useBuffer(...) sliced
the ring entry using that raw total instead of clamping it to the
entry's own writable capacity, so retainedSlice(...) threw an
IndexOutOfBoundsException on the io_uring event-loop thread. The
exception propagated out before the buffer-ring bookkeeping (freeing the
bid, releasing the buffer, decrementing usableBuffers) ran, leaking a
direct buffer and leaving the channel's multishot receive armed to
repeat the fault on every subsequent oversized burst.

Modifications:

Clamp the slice length and writerIndex advance in useBuffer(...) to
byteBuf.writableBytes(), matching the method's documented contract that
callers loop over the remainder via nextBid(...). Add a regression test
exercising useBuffer(...) directly with a read larger than a single
entry's capacity, and switch the test class to AssertJ assumptions.

Result:

useBuffer(...) no longer throws when a bundle completion spans more
than one ring entry.

@normanmaurer normanmaurer added this to the 4.2.19.Final milestone Sep 21, 2026
Motivation:

When IORING_RECVSEND_BUNDLE is enabled, a single completion can report
a byte count spanning multiple buffer-ring entries. useBuffer(...) sliced
the ring entry using that raw total instead of clamping it to the
entry's own writable capacity, so retainedSlice(...) threw an
IndexOutOfBoundsException on the io_uring event-loop thread. The
exception propagated out before the buffer-ring bookkeeping (freeing the
bid, releasing the buffer, decrementing usableBuffers) ran, leaking a
direct buffer and leaving the channel's multishot receive armed to
repeat the fault on every subsequent oversized burst.

Modifications:

Clamp the slice length and writerIndex advance in useBuffer(...) to
byteBuf.writableBytes(), matching the method's documented contract that
callers loop over the remainder via nextBid(...). Add a regression test
exercising useBuffer(...) directly with a read larger than a single
entry's capacity, and switch the test class to AssertJ assumptions.

Result:

useBuffer(...) no longer throws when a bundle completion spans more
than one ring entry.
@normanmaurer
normanmaurer force-pushed the io-uring-buffer-ring-fix-6939f216 branch from e4b734a to 25524bb Compare September 21, 2026 10:37
@testlens-app

testlens-app Bot commented Sep 21, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 25524bb
▶️ Tests: 463475 executed
⚪️ Checks: 26/26 completed


Learn more about TestLens at testlens.app/docs.

@normanmaurer
normanmaurer merged commit e79185a into 4.2 Sep 21, 2026
27 checks passed
@normanmaurer
normanmaurer deleted the io-uring-buffer-ring-fix-6939f216 branch September 21, 2026 18:54
@normanmaurer normanmaurer added the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Sep 21, 2026
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

@normanmaurer

Copy link
Copy Markdown
Member Author

Port for 5.0: #17584

normanmaurer added a commit that referenced this pull request Sep 22, 2026
) (#17584)

Motivation:

When IORING_RECVSEND_BUNDLE is enabled, a single completion can report
a byte count spanning multiple buffer-ring entries. useBuffer(...)
sliced
the ring entry using that raw total instead of clamping it to the
entry's own writable capacity, so retainedSlice(...) threw an
IndexOutOfBoundsException on the io_uring event-loop thread. The
exception propagated out before the buffer-ring bookkeeping (freeing the
bid, releasing the buffer, decrementing usableBuffers) ran, leaking a
direct buffer and leaving the channel's multishot receive armed to
repeat the fault on every subsequent oversized burst.

Modifications:

Clamp the slice length and writerIndex advance in useBuffer(...) to
byteBuf.writableBytes(), matching the method's documented contract that
callers loop over the remainder via nextBid(...). Add a regression test
exercising useBuffer(...) directly with a read larger than a single
entry's capacity, and switch the test class to AssertJ assumptions.

Result:

useBuffer(...) no longer throws when a bundle completion spans more
than one ring entry.
@normanmaurer normanmaurer removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants