Summary With IORING_RECVSEND_BUNDLE, one completion can span several consecutive provided-buffer ring entries
Description
With IORING_RECVSEND_BUNDLE, one completion can span several consecutive provided-buffer ring entries. AbstractIoUringStreamChannel walks them with bid = bufferRing.nextBid(bid), and IoUringBufferRing.nextBid (IoUringBufferRing.java:271-273) computes (bid + 1) & (allocatedBuffers - 1). That equals (bid + 1) % allocatedBuffers only when allocatedBuffers is a power of two and hasn't changed since the kernel consumed the entries. Two reachable states break it:
- A. Non-power-of-two ring.
IoUringBufferRingConfigaccepts anybatchSizein[1, ringSize], and the ring grows bybatchSizeper expansion. For example,ringSize=16, batchSize=4goes 4 → 8 → 12 → 16. AtallocatedBuffers=12,nextBid(3) = 4 & 11 = 0(should be 4), andnextBid(11) = 12 & 11 = 8(should be 0). - B. Expansion during a bundle. The
useBuffer(bid)call that empties the ring growsallocatedBuffersbefore the caller asksnextBid(bid)(IoUringBufferRing.java:241-266). WithbatchSize = ringSize/2, a bundle spanning bid 7 → 0 seesallocatedBuffersgo 8 → 16, sonextBid(7) = 8(should be 0).
Impact
In both cases Netty reads the wrong ring slot:
- The rest of the received data is taken from a different buffer, possibly one still posted for other reads (wrong or foreign data delivered to the pipeline).
- The buffer the kernel actually filled is never delivered and its bid is never recycled (buffer leak / ring stall).
- A ring entry can be left pointing at a buffer Netty has already released, so a later kernel write would go into released memory (possible use-after-free).
A remote peer only has to send data in a pattern that produces bundle completions.
Preconditions (these limit exposure):
RECVSEND_BUNDLEis disabled by default inIoUring(io.netty.iouring.recvsendBundleEnabled=false, because of a known kernel bug). Only users who opt in are affected.- It needs the io_uring transport with a provided buffer ring (
IoUringBufferRingConfig). Scenario A needsbatchSize < ringSize/2. - Linux only.
Reproduction
I didn't run this against a real Linux kernel. I compiled the real transport-classes-io_uring sources against a small JNI stub and drove useBuffer/nextBid with a simulated kernel that consumes consecutive ring entries. The ring memory layout and the bid arithmetic are pure Java.
== scenario A, batchSize 4
after ENOBUFS round 1: allocatedBuffers=12
kernel filled bids 3,4 (consecutive ring entries), allocatedBuffers=12
nextBid(3) = 0 (kernel used bid 4)
delivered to pipeline: [bid 3: AAAAAAAA] [bid 0: ........]
== scenario B, default batchSize
kernel bundle used bids 7,0
allocatedBuffers now 16; nextBid(7) = 8 (kernel used bid 0)
delivered to pipeline: [bid 7: AAAAAAAA] [bid 8: ........]
kernel-filled buffer of bid 0 never delivered and never recycled: truebatchSize 8 on a 16-entry ring, where allocatedBuffers is always a power of two, behaves correctly. This is a sibling of #17568 (the missing per-entry clamp in useBuffer), in the same RECVSEND_BUNDLE multi-entry path.
Suggested fix
Don't derive the next bid from the current allocatedBuffers. Either:
- mask by the fixed ring size (
entries, always a power of two) and don't grow the ring in the middle of a bundle walk (defer the expansion until the bundle loop inAbstractIoUringStreamChannelfinishes), or - track the bid sequence of the bundle explicitly.
Also consider keeping allocatedBuffers a power of two, for example by growing in power-of-two steps.
--- Found by modelling the arithmetic in Lean 4 and reproducing it against the real classes on 4.2 HEAD (cd967a41). The same code is on 5.0 (and 4.1 where the class exists) as of 2026-09-23. Reported by @allthingssecurity; the analysis and this report were prepared with Claude Code (Claude Opus 5.5). A patch with regression tests can follow once you confirm how you want to handle it.