Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH rdma-rc] RDMA/rxe: Fail ATOMIC_WRITE WQEs whose length is not 8 bytes
@ 2026-11-23 14:06 Andrew Stellman
  2026-11-23 14:19 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Stellman @ 2026-11-23 14:06 UTC (permalink / raw)
  To: Zhu Yanjun
  Cc: Zhu Yanjun, Jason Gunthorpe, Leon Romanovsky, Xiao Yang,
	linux-rdma, linux-kernel

For IB_WR_ATOMIC_WRITE, rxe_requester() uses wqe->dma.resid as the
payload length and finish_packet() copies that many bytes (up to the
path MTU) from wqe->dma.atomic_wr, which holds 8 bytes. For a user QP,
resid is written by userspace in the mmap'd send ring and is not
checked.

On x86_64 v7.4-rc3 under QEMU with KASAN, an unprivileged user wrote
an ATOMIC_WRITE WQE with resid 1024 into the last send ring slot of an
RC QP. KASAN reported a vmalloc-out-of-bounds read of size 1024 in
rxe_requester(). With resid 64 and 1024 in another slot, a test-only
printk in the responder showed packets of 64 and 1024 bytes, including
bytes I had placed after the value in the slot. The sender's completion
was IB_WC_REM_INV_REQ_ERR. With resid 8 the write succeeded.

The responder already rejects an ATOMIC_WRITE whose length is not 8.
Make the requester fail such a WQE with IB_WC_LOC_QP_OP_ERR before
building the packet. With this patch, resid 64 and 1024 (in another
slot and in the last slot) completed with IB_WC_WR_FLUSH_ERR instead of
IB_WC_REM_INV_REQ_ERR, resid 4 also completed with IB_WC_WR_FLUSH_ERR,
KASAN reported nothing, and resid 8 still succeeded.

The issue was found by Claude Opus 5.5 running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix and this changelog were drafted with Claude Sonnet 5.5 and reviewed by me.

Fixes: abb633cf2804 ("RDMA/rxe: Make requester support atomic write on RC service")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.

 drivers/infiniband/sw/rxe/rxe_req.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c
index 4f353abd7..bc3d5cae5 100644
--- a/drivers/infiniband/sw/rxe/rxe_req.c
+++ b/drivers/infiniband/sw/rxe/rxe_req.c
@@ -766,6 +766,11 @@ int rxe_requester(struct rxe_qp *qp)
 	mtu = get_mtu(qp);
 	payload = (mask & (RXE_WRITE_OR_SEND_MASK | RXE_ATOMIC_WRITE_MASK)) ?
 			wqe->dma.resid : 0;
+	/* use the local copies: a user QP's WQE can change under us */
+	if ((mask & RXE_ATOMIC_WRITE_MASK) && payload != sizeof(u64)) {
+		wqe->status = IB_WC_LOC_QP_OP_ERR;
+		goto err;
+	}
 	if (payload > mtu) {
 		if (qp_type(qp) == IB_QPT_UD) {
 			/* C10-93.1.1: If the total sum of all the buffer lengths specified for a
-- 
2.43.0


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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:06 [PATCH rdma-rc] RDMA/rxe: Fail ATOMIC_WRITE WQEs whose length is not 8 bytes Andrew Stellman
2026-11-23 14: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