Re: [PATCH] io_uring: fix CQ tail over-commit and CQE32 index corruption in io_cqe_cache_refill()

From: Jens Axboe

Date: Mon Sep 21 2026 - 12:16:57 EST


On 9/19/26 2:35 PM, Hui Peng wrote:
> io_cqe_cache_refill() has three issues when handling 32-byte CQEs on
> IORING_SETUP_CQE32 and IORING_SETUP_CQE_MIXED rings:

Don't combine fixes, send 3 separate patches.

> 1. When cqe32 is true and off + 1 == ctx->cq_entries,
> io_cqe_cache_refill() posts a 16-byte dummy IORING_CQE_F_SKIP CQE via
> io_fill_nop_cqe(ctx, off) even on pure IORING_SETUP_CQE32 rings
> (where IORING_SETUP_CQE_MIXED is not set). On a pure CQE32 ring,
> ctx->cq_entries is the number of 32-byte CQEs and rings->cqes is
> indexed by (off << 1), so writing a 16-byte skip CQE at
> &rings->cqes[off] corrupts the middle of the CQ ring and misaligns
> all subsequent CQEs. Restrict the wrap-around skip CQE to
> IORING_SETUP_CQE_MIXED rings.
>
> 2. On an IORING_SETUP_CQE_MIXED ring, when off + 1 == ctx->cq_entries
> and only 1 free CQ slot remains (ctx->cq_entries - io_cqring_queued()
> == 1), io_fill_nop_cqe(ctx, off) consumes that last slot and
> increments ctx->cached_cq_tail, after which free == 0 causes
> io_cqe_cache_refill() to return false without updating
> ctx->cqe_cached. Check that at least 2 free CQ slots exist before
> posting the dummy skip CQE.

These two look fine.

> 3. On pure IORING_SETUP_CQE32 rings, len is in 32-byte CQE units prior
> to `len <<= 1`, so `len < (cqe32 + 1)` falsely requires 2 free
> 32-byte CQEs instead of 1. Check `!len` before scaling `off` and
> `len` on IORING_SETUP_CQE32 rings, and in io_fill_cqe_aux() zero
> cqe->big_cqe[0..1] whenever IORING_SETUP_CQE32 is set on the ring.

This part looks wrong.

--
Jens Axboe