Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/siw: don't complete a fenced READ twice on flush
@ 2026-11-25  6:06 Cygnus Qiu
  2026-11-25  6:19 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Cygnus Qiu @ 2026-11-25  6:06 UTC (permalink / raw)
  To: bernard.metzler, jgg, leon
  Cc: cel, linux-nfs, linux-rdma, linux-kernel, Cygnus Qiu, stable

siw_sq_flush() completes the READ in the TX slot while it is still
SIW_WR_QUEUED, assuming a queued READ is not in the ORQ yet. That only
holds when a full ORQ fenced it. siw_activate_tx_from_sq() copies a READ
into a free ORQ slot, and siw_check_tx_fence() copies a fenced READ into
the ORQ once a Read Response frees a slot; in both cases the WQE stays
QUEUED until the TX path sends the Read Request. A flush in that window
completes the READ from the ORQ and again from the TX slot: two
IB_WC_WR_FLUSH_ERR completions for one work request.

The peer controls the window. It advertises IRD 1, so the ORQ holds one
READ, and answers the first Read Request with a Read Response and a FIN
in one TCP segment: the FIN suspends TX before the Read Response moves
the next READ into the ORQ, and the close flushes it.

svcrdma's svc_rdma_wc_read_done() then puts the receive context twice,
which links it into sc_recv_ctxts as a loop, and svc_rdma_free() reads
it after freeing it and frees it a second time, a double free. svcrdma
pulls the Read chunk before it decodes the RPC, so the peer needs no
RPC credentials and no export access.

Complete a QUEUED READ from the TX slot only while the ORQ fence is set.

Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix
and this changelog were also drafted with LLM assistance. Reproduced on
an unmodified KASAN build of mainline: a plain TCP client sends nfsd's
svcrdma listener on siw an RDMA_NOMSG call whose Read chunk has two
segments and answers the first Read Request as above.
svcrdma_wc_read_flush fires twice for the chunk (5 of 5 runs), then:

  BUG: KASAN: slab-use-after-free in llist_del_first+0x150/0x170
  Read of size 8 at addr ffff8881119d9000 by task nfsd/183
   llist_del_first+0x150/0x170
   svc_rdma_recv_ctxts_destroy+0xf3/0x1b0
   svc_rdma_free+0xd8/0x2e0
   svc_xprt_free+0x22c/0x420
  Freed by task 183:
   kfree+0x162/0x500
   svc_rdma_recv_ctxts_destroy+0xe7/0x1b0

Without KASAN and with SLAB_FREELIST_HARDENED, the double free is
caught as "kernel BUG at mm/slub.c:605" in kfree() from
svc_rdma_recv_ctxts_destroy() (4 of 4 runs).

With this patch the chunk is flushed once and KASAN stays silent (4 of 4
runs). The rdma-core tests could not run: the siw provider of rdma-core
66 fails an assertion in siw_destroy_cq() on the first test, with and
without this patch.

Fixes: f29dd55b0236 ("rdma/siw: queue pair methods")
Cc: stable@vger.kernel.org
Signed-off-by: Cygnus Qiu <eritque-arcus@ikuyo.dev>
---
Tested on mainline 4405c18c95d2 (v7.4-rc3+) in QEMU. Applies to
mainline 8d7fe9885c62.

Sending the FIN only after the second Read Request has gone out, or
with no Read Response at all (the fenced READ never enters the ORQ),
gives one flush completion before and after the patch.

siw_sq_flush() now relies on orq_fence. That bit shares a byte with
tx_suspend, which siw_cm_llp_state_change() sets without the QP state
lock. A lost update there already stalls the fenced READ in
siw_check_tx_fence(); with this patch it would also lose that READ's
flush completion. I did not try to hit that window.

A reproducer and the test logs are available on request.

 drivers/infiniband/sw/siw/siw_qp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c
index bb780e3904..2cc0f466e7 100644
--- a/drivers/infiniband/sw/siw/siw_qp.c
+++ b/drivers/infiniband/sw/siw/siw_qp.c
@@ -1188,10 +1188,11 @@ void siw_sq_flush(struct siw_qp *qp)
 		if (tx_type(wqe) != SIW_OP_READ_RESPONSE &&
 		    ((tx_type(wqe) != SIW_OP_READ &&
 		      tx_type(wqe) != SIW_OP_READ_LOCAL_INV) ||
-		     wqe->wr_status == SIW_WR_QUEUED))
+		     (wqe->wr_status == SIW_WR_QUEUED &&
+		      qp->tx_ctx.orq_fence)))
 			/*
-			 * An in-progress Read Request is already in
-			 * the ORQ
+			 * A Read Request is already in the ORQ unless
+			 * a full ORQ fenced it
 			 */
 			siw_sqe_complete(qp, &wqe->sqe, wqe->bytes,
 					 SIW_WC_WR_FLUSH_ERR);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25  6:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  6:06 [PATCH] RDMA/siw: don't complete a fenced READ twice on flush Cygnus Qiu
2026-11-25  6:19 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox