public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Zizhi Wo <wozizhi@huaweicloud.com>,
	asml.silence@gmail.com, io-uring@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, yangerkun@huawei.com,
	chengzhihao1@huawei.com
Subject: Re: [PATCH] io_uring: validate user-controlled cq.head in io_cqe_cache_refill()
Date: Wed, 13 May 2026 08:18:00 -0600	[thread overview]
Message-ID: <f8dc69f8-7191-4c60-a2a3-2fa85a089927@kernel.dk> (raw)
In-Reply-To: <20260513063254.1122354-1-wozizhi@huaweicloud.com>

On 5/13/26 12:32 AM, Zizhi Wo wrote:
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> index 4ed998d60c09..92e255e9e08f 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -710,11 +710,13 @@ static bool io_fill_nop_cqe(struct io_ring_ctx *ctx, unsigned int off)
>   * fill the cq entry
>   */
>  bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32)
>  {
>  	struct io_rings *rings = ctx->rings;
> -	unsigned int off = ctx->cached_cq_tail & (ctx->cq_entries - 1);
> +	unsigned int head = READ_ONCE(ctx->rings->cq.head);
> +	unsigned int tail = ctx->cached_cq_tail;
> +	unsigned int off = tail & (ctx->cq_entries - 1);
>  	unsigned int free, queued, len;

This looks wrong, as you're snapshotting 'tail' while it could get
modified by if a nop fill before the refill happens. And fwiw, looks
like the refill part potentially suffers from the same unsigned issue.

-- 
Jens Axboe

  reply	other threads:[~2026-05-13 14:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  6:32 [PATCH] io_uring: validate user-controlled cq.head in io_cqe_cache_refill() Zizhi Wo
2026-05-13 14:18 ` Jens Axboe [this message]
2026-05-13 14:20   ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8dc69f8-7191-4c60-a2a3-2fa85a089927@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=asml.silence@gmail.com \
    --cc=chengzhihao1@huawei.com \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wozizhi@huaweicloud.com \
    --cc=yangerkun@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox