Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shuai Liu" <847807867@qq.com>, linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next v1] RDMA/rxe: Don't trust the user space SQ producer index
Date: Fri, 20 Nov 2026 12:02:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-225106@kernel.org> (raw)
In-Reply-To: <tencent_5B9FB1BCC8EF36C5E2128B7D4D54B867480A@qq.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] RDMA/rxe: requester and completer SQ index desync on
  out-of-range prod
- [Medium] RDMA/rxe: unvalidated SQ producer index read in
  rxe_qp_init_req()
- [Low] RDMA/rxe: wrong Fixes trailer and IB_QPS_ERR loop description
--

commit 216db84647f6c90b4699ba426a623f31c2b768e8
Author: Shuai Liu <847807867@qq.com>

> RDMA/rxe: Don't trust the user space SQ producer index
>
> The send queue producer index of a user space QP is stored in the
> queue buffer which is shared with and written by user space. The
> requester reads it without any validation in req_retry() and
> __req_next_wqe().
>
> The requester stops processing WQEs when its local WQE index equals
> the producer index. If user space writes an out of range producer
> index into the queue buffer, that comparison can never become true.
> Once the QP is put into the error state, rxe_requester() then keeps
> flushing the same (already errored) WQE forever: the flush loop
> advances the WQE index but req_retry() resets it back to the
> consumer index, and each pass calls rxe_qp_error() which reschedules
> the send task, so the loop never converges. The send task holds a
> reference to the QP for as long as this lasts, so ib_destroy_qp()
> waits for the QP reference to drop until it times out after 50
> seconds and the WARN_ON(!ret) fires in __rxe_cleanup():
>
>   WARNING: drivers/infiniband/sw/rxe/rxe_pool.c:212 at __rxe_cleanup
>   Call Trace:
>    __rxe_cleanup
>    rxe_destroy_qp
>    ...
>   rxe0: qp#17 rxe_destroy_qp: cleanup failed, err = -110
>
> Fix this by validating the producer index: if it is out of range,
> treat the send queue as empty. Verified with the syzbot reproducer
> in QEMU: without this patch every destroy_qp hangs for 50 seconds
> and hits the WARNING above; with this patch the reproducer runs
> cleanly.
>
> Reported-by: syzbot+fef38133c495aeb48297@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=fef38133c495aeb48297
> Fixes: 5bcf5a59c41e1 ("RDMA/rxe: Protext kernel index from user space")
> Signed-off-by: Shuai Liu <847807867@qq.com>

[Severity: Low]
Should the Fixes tag point to ae6e843fe08d ("RDMA/rxe: Add memory barriers
to kernel queues") instead?  In 5bcf5a59c41e ("RDMA/rxe: Protext kernel
index from user space"), producer_index() still masked the user-space value
with q->index_mask; ae6e843fe08d ("RDMA/rxe: Add memory barriers to kernel
queues") replaced producer_index() with queue_get_producer() and dropped
that mask.

Also, when qp_state(qp) == IB_QPS_ERR, rxe_requester() jumps directly to
err: or exit: without reaching req_retry(); qp->req.wqe_index wraps back to
the consumer index via queue_next_index() at err: because queue_next_index()
masks with q->index_mask and never matches the out-of-range prod.

> diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c
> index 6e01fb18893bf..4a78562d83b19 100644
> --- a/drivers/infiniband/sw/rxe/rxe_req.c
> +++ b/drivers/infiniband/sw/rxe/rxe_req.c
> @@ -48,6 +48,12 @@ static void req_retry(struct rxe_qp *qp)
>  	cons = queue_get_consumer(q, QUEUE_TYPE_FROM_CLIENT);
>  	prod = queue_get_producer(q, QUEUE_TYPE_FROM_CLIENT);
>  
> +	/* The producer index is written by user space and cannot
> +	 * be trusted; treat an out of range index as an empty queue.
> +	 */
> +	if (unlikely(prod & ~q->index_mask))
> +		prod = cons;
> +
>  	qp->req.wqe_index	= cons;
>  	qp->req.psn		= qp->comp.psn;
>  	qp->req.opcode		= -1;
> @@ -188,7 +194,7 @@ static struct rxe_send_wqe *__req_next_wqe(struct rxe_qp *qp)
>  	unsigned int prod;
>  
>  	prod = queue_get_producer(q, QUEUE_TYPE_FROM_CLIENT);
> -	if (index == prod)
> +	if (unlikely(prod & ~q->index_mask) || index == prod)
>  		return NULL;
>  	else
>  		return queue_addr_from_index(q, index);

[Severity: Medium]
Can treating out-of-range prod as an empty queue here desynchronize
qp->req.wqe_index from the completer's consumer index q->index?

queue_empty() in drivers/infiniband/sw/rxe/rxe_queue.h masks the index
difference with q->index_mask:

drivers/infiniband/sw/rxe/rxe_queue.h:queue_empty() {
	u32 prod = queue_get_producer(q, type);
	u32 cons = queue_get_consumer(q, type);

	return ((prod - cons) & q->index_mask) == 0;
}

When user space writes a producer index where (prod & ~q->index_mask) != 0
and ((prod - cons) & q->index_mask) != 0, __req_next_wqe() treats the queue
as empty and leaves qp->req.wqe_index at cons, while rxe_completer()
(via get_wqe() or flush_send_queue() -> queue_head() -> queue_empty()) sees
a non-empty queue and advances cons to prod & q->index_mask.  If user space
then writes an in-range prod equal to the new cons, __req_next_wqe() sees
index != prod and processes or flushes already-consumed and unposted WQE
slots across the ring buffer.

In addition, if WQEs are already in flight (cons != qp->req.wqe_index) when
user space sets upper bits in prod, clamping prod = cons in req_retry()
rewinds qp->req.wqe_index to cons and qp->req.psn to qp->comp.psn while
skipping the retry loop, leaving those in-flight WQEs stuck in
wqe_state_pending with exhausted DMA residuals.

Masking prod with q->index_mask in queue_get_producer() for
QUEUE_TYPE_FROM_CLIENT (as producer_index() did prior to ae6e843fe08d
("RDMA/rxe: Add memory barriers to kernel queues")) would keep the
requester, completer, and queue helpers consistent.

[Severity: Medium]
Does rxe_qp_init_req() also read an unvalidated user producer index into
qp->req.wqe_index?

drivers/infiniband/sw/rxe/rxe_qp.c:rxe_qp_init_req() {
	...
	err = rxe_init_sq(qp, init, udata, uresp);
	if (err)
		return err;

	qp->req.wqe_index = queue_get_producer(qp->sq.queue,
					       QUEUE_TYPE_FROM_CLIENT);
	...
}

rxe_init_sq() calls do_mmap_info(), which copies the mmap info to user space
and registers it in rxe->pending_mmaps before returning.  If user space maps
the buffer and writes to q->buf->producer_index before rxe_qp_init_req()
reads it, qp->req.wqe_index is initialized to an unvalidated value while
the consumer index q->index starts at 0, so a subsequent valid prod == 0
causes __req_next_wqe() to see index != prod and process unposted WQE slots
on an empty queue.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_5B9FB1BCC8EF36C5E2128B7D4D54B867480A@qq.com?part=1

      reply	other threads:[~2026-11-20 12:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 12:35 [syzbot] [rdma?] WARNING in __rxe_cleanup syzbot
2026-10-24  3:31 ` Zhu Yanjun
2026-11-19 21:03 ` syzbot
2026-11-20 11:42 ` [PATCH rdma-next v1] RDMA/rxe: Don't trust the user space SQ producer index Shuai Liu
2026-11-20 12:02   ` sashiko-bot [this message]

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=sashiko-outbox-225106@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=847807867@qq.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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