Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Shuai Liu <847807867@qq.com>
To: linux-rdma@vger.kernel.org
Cc: yanjun.zhu@linux.dev, zyjzyj2000@gmail.com, jgg@ziepe.ca,
	leon@kernel.org, rpearsonhpe@gmail.com,
	syzbot+fef38133c495aeb48297@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org,
	sashiko-reviews@lists.linux.dev
Subject: [PATCH] RDMA/rxe: Mask the SQ producer index read from user space
Date: Sat, 21 Nov 2026 11:42:04 +0800	[thread overview]
Message-ID: <tencent_03B85262EE136CEE83D2012CA5F2704D2008@qq.com> (raw)
In-Reply-To: <tencent_5B9FB1BCC8EF36C5E2128B7D4D54B867480A@qq.com>

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() and compares it against its own local index which
is always masked.

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 WQEs forever: the flush path advances the WQE index with the
masked queue_next_index() but the producer index stays out of range,
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 masking the producer index with q->index_mask when reading
it in queue_get_producer() for QUEUE_TYPE_FROM_CLIENT. This restores
what producer_index() did before commit ae6e843fe08d ("RDMA/rxe: Add memory
barriers to kernel queues") replaced it with queue_get_producer() and
dropped the mask, and keeps the requester, the completer and the queue
helpers, which all compare the difference of the two indices modulo
index_mask, consistent. rxe_qp_init_req() also initializes
qp->req.wqe_index from this value so it gets validated as well.

Masking the index in queue_get_producer() instead of checking it at
the two requester call sites was suggested by the Sashiko AI review of
v1 of this patch.

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: ae6e843fe08d ("RDMA/rxe: Add memory barriers to kernel queues")
Signed-off-by: Shuai Liu <847807867@qq.com>
---
Changes since v1:
- Mask the producer index in queue_get_producer() for
  QUEUE_TYPE_FROM_CLIENT instead of checking it at the two requester
  call sites, as suggested by the Sashiko AI review of v1. This also
  covers rxe_qp_init_req(), which initializes qp->req.wqe_index from
  the same value, and keeps the requester, the completer and the queue
  helpers consistent with each other.
- Point Fixes at commit ae6e843fe08d, which dropped the mask that
  producer_index() had, instead of commit 5bcf5a59c41e.
- Reword the commit message: the flush loop never converges because
  the WQE index is advanced with the masked queue_next_index() while
  the producer index stays out of range; the req_retry() reset detail
  in the v1 description was inaccurate.
- Update the subject to describe the actual mechanism.

 drivers/infiniband/sw/rxe/rxe_queue.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/infiniband/sw/rxe/rxe_queue.h b/drivers/infiniband/sw/rxe/rxe_queue.h
index c711cb98b9496..fe65aecc60464 100644
--- a/drivers/infiniband/sw/rxe/rxe_queue.h
+++ b/drivers/infiniband/sw/rxe/rxe_queue.h
@@ -106,6 +106,7 @@ static inline u32 queue_get_producer(const struct rxe_queue *q,
 	case QUEUE_TYPE_FROM_CLIENT:
 		/* used by rxe, client owns the index */
 		prod = smp_load_acquire(&q->buf->producer_index);
+		prod &= q->index_mask;
 		break;
 	case QUEUE_TYPE_TO_CLIENT:
 		/* used by rxe which owns the index */
-- 
2.43.0


  parent reply	other threads:[~2026-11-21  3:42 UTC|newest]

Thread overview: 9+ 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
2026-11-21  3:42   ` Shuai Liu [this message]
2026-11-21  3:48     ` [PATCH] RDMA/rxe: Mask the SQ producer index read from user space sashiko-bot
2026-11-21  3:46   ` [PATCH rdma-next v2] " Shuai Liu
2026-11-21  3:51     ` sashiko-bot

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=tencent_03B85262EE136CEE83D2012CA5F2704D2008@qq.com \
    --to=847807867@qq.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rpearsonhpe@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=syzbot+fef38133c495aeb48297@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=yanjun.zhu@linux.dev \
    --cc=zyjzyj2000@gmail.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