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

* Re: [PATCH rdma-rc] RDMA/rxe: Fail ATOMIC_WRITE WQEs whose length is not 8 bytes
  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
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 14:19 UTC (permalink / raw)
  To: Andrew Stellman; +Cc: linux-rdma

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] RDMA/rxe: unreachable atomic write length check in
  rxe_requester()
--

commit 53a7ca51888beabddbfd557ad8447b0102b0d59e
Author: Andrew Stellman <astellman@stellman-greene.com>

RDMA/rxe: Fail ATOMIC_WRITE WQEs whose length is not 8 bytes

This commit adds a check in rxe_requester() to fail IB_WR_ATOMIC_WRITE
WQEs with IB_WC_LOC_QP_OP_ERR when the payload length is not sizeof(u64).

> diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c
> index 6e01fb18893bf..962aef824ccc2 100644
> --- a/drivers/infiniband/sw/rxe/rxe_req.c
> +++ b/drivers/infiniband/sw/rxe/rxe_req.c
> @@ -824,6 +824,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;
> +	}

[Severity: Medium]
Can payload ever differ from sizeof(u64) here when RXE_ATOMIC_WRITE_MASK
is set?

Earlier in rxe_requester(), req_next_wqe() copies the WQE into the
kernel-private buffer qp->req.send_wqe.wqe and forces wqe->dma.resid to
sizeof(u64) for atomic writes (added in a668a8564748 ("RDMA/rxe: copy
send WQE to kernel buffer before processing")):

drivers/infiniband/sw/rxe/rxe_req.c:req_next_wqe() {
    ...
	if (unlikely((wqe->mask & WR_ATOMIC_WRITE_MASK) &&
		     wqe->dma.resid != sizeof(u64)))
		wqe->dma.resid = sizeof(u64);
	return wqe;
}

As a result, this new check is unreachable, and an IB_WR_ATOMIC_WRITE WQE
with wqe->dma.resid != sizeof(u64) will still be clamped and sent as an
8-byte atomic write instead of failing with IB_WC_LOC_QP_OP_ERR.

Also, because this check runs after check_init_depth(), if the clamping in
req_next_wqe() is removed, a malformed atomic write WQE would consume or
stall on rd_atomic credits before failing.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123140625.64448-1-astellman@stellman-greene.com?part=1

^ permalink raw reply	[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