All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH rdma-rc] RDMA/siw: Reject opcodes a user send queue may not use
@ 2026-11-20  0:02 Andrew Stellman
  2026-11-20  0:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Stellman @ 2026-11-20  0:02 UTC (permalink / raw)
  To: Bernard Metzler
  Cc: Jason Gunthorpe, Leon Romanovsky, linux-rdma, linux-kernel

A user QP's send queue is mapped into the process, and
siw_activate_tx_from_sq() only checks that an SQE's opcode is below
SIW_NUM_OPCODES. siw-abi.h marks SIW_OP_INVAL_STAG and SIW_OP_REG_MR as
valid for in-kernel clients only, but a user process can still post
them. For SIW_OP_REG_MR, siw_fastreg_mr() then uses the user supplied
base_mr value as a kernel pointer to a struct ib_mr.

The uverbs device is mode 0666, so once an administrator has created a
siw device any local user can trigger this. With an unmapped base_mr,
as an unprivileged user under KASAN:

  Oops: general protection fault, probably for non-canonical address 0xe000042828282002: 0000 [#1] SMP KASAN NOPTI
  KASAN: probably user-memory-access in range [0x0000414141410010-0x0000414141410017]
  RIP: 0010:siw_qp_sq_process+0x38b/0x3c10
  Call Trace:
   <TASK>
   siw_post_send+0xecf/0x20b0
   ib_uverbs_post_send+0xf28/0x1610
   ib_uverbs_write+0x899/0xd30
   vfs_write+0x227/0xcd0
   ksys_write+0x17c/0x1c0
   do_syscall_64+0xdf/0x4c0

The task is killed, and then hangs in siw_destroy_qp() when its files
are closed on exit. Posting an unsupported atomic or SIW_OP_RECEIVE
instead hits the WARN(1, "undefined WQE type") in siw_qp_sq_process()
and leaves the memory region named in the SQE pinned after the process
exits.

No opcode from SIW_OP_FETCH_AND_ADD up is valid on a user send queue,
so reject them all.

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 the same tool and reviewed
by me.

Fixes: f29dd55b0236 ("rdma/siw: queue pair methods")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---

Tested in QEMU with KASAN on v7.4-rc3. The patch applies unchanged to
rdma for-rc. With this patch the post returns -EINVAL for REG_MR,
INVAL_STAG, FETCH_AND_ADD and RECEIVE from a user QP, user SEND and RDMA
WRITE still complete, and rping over siw works.
A reproducer is available on request.

 drivers/infiniband/sw/siw/siw_qp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c
index bb780e3904a2..10876cefc0bb 100644
--- a/drivers/infiniband/sw/siw/siw_qp.c
+++ b/drivers/infiniband/sw/siw/siw_qp.c
@@ -869,6 +869,12 @@ static int siw_activate_tx_from_sq(struct siw_qp *qp)
 		rv = -EINVAL;
 		goto out;
 	}
+	/* No opcode from FETCH_AND_ADD up is valid on a user SQ */
+	if (!rdma_is_kernel_res(&qp->base_qp.res) &&
+	    wqe->sqe.opcode >= SIW_OP_FETCH_AND_ADD) {
+		rv = -EINVAL;
+		goto out;
+	}
 	if (wqe->sqe.flags & SIW_WQE_INLINE) {
 		if (wqe->sqe.opcode != SIW_OP_SEND &&
 		    wqe->sqe.opcode != SIW_OP_WRITE) {

base-commit: e7732ec135b501e87ab060d992b3b5f2ec4396c9
-- 
2.43.0


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

* Re: [PATCH rdma-rc] RDMA/siw: Reject opcodes a user send queue may not use
  2026-11-20  0:02 [PATCH rdma-rc] RDMA/siw: Reject opcodes a user send queue may not use Andrew Stellman
@ 2026-11-20  0:07 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-20  0:07 UTC (permalink / raw)
  To: Andrew Stellman; +Cc: linux-rdma

> A user QP's send queue is mapped into the process, and
> siw_activate_tx_from_sq() only checks that an SQE's opcode is below
> SIW_NUM_OPCODES. siw-abi.h marks SIW_OP_INVAL_STAG and SIW_OP_REG_MR as
> valid for in-kernel clients only, but a user process can still post
> them. For SIW_OP_REG_MR, siw_fastreg_mr() then uses the user supplied
> base_mr value as a kernel pointer to a struct ib_mr.
> 
> The uverbs device is mode 0666, so once an administrator has created a
> siw device any local user can trigger this. With an unmapped base_mr,
> as an unprivileged user under KASAN:
> 
>   Oops: general protection fault, probably for non-canonical address 0xe000042828282002: 0000 [#1] SMP KASAN NOPTI
>   KASAN: probably user-memory-access in range [0x0000414141410010-0x0000414141410017]
>   RIP: 0010:siw_qp_sq_process+0x38b/0x3c10
>   Call Trace:
> [ ... ]
> The fix and this changelog were drafted with the same tool and reviewed
> by me.
> 
> Fixes: f29dd55b0236 ("rdma/siw: queue pair methods")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>

Sashiko has reviewed this patch and found no issues.

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


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

end of thread, other threads:[~2026-11-20  0:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  0:02 [PATCH rdma-rc] RDMA/siw: Reject opcodes a user send queue may not use Andrew Stellman
2026-11-20  0:07 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.