Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]
       [not found] <20260930182216.2510953-1-ays511.kr@gmail.com>
@ 2026-10-01 15:24 ` Youngsung Ahn
  2026-10-01 16:15   ` Leon Romanovsky
  2026-10-15 13:59   ` Leon Romanovsky
  0 siblings, 2 replies; 3+ messages in thread
From: Youngsung Ahn @ 2026-10-01 15:24 UTC (permalink / raw)
  To: Zhu Yanjun; +Cc: linux-rdma, Youngsung Ahn, stable

For a user QP, rxe_post_send() takes the qp->is_user branch and
never runs init_send_wqe(), so
dma.length/resid/num_sge/cur_sge/sge_offset all come straight from
the mmap'd SQ ring. In the inline send path finish_packet() uses
sge_offset directly as an index:

	u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset];
	memcpy(payload_addr(pkt), tmp, payload);

inline_data is a flex array whose capacity is qp->sq.max_inline, but
sge_offset is a u32 from user space, so the source pointer is
displaced arbitrarily past the WQE and the memcpy reads out of
bounds.
commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]")
added num_sge/cur_sge checks on the send path but not sge_offset, the
third attacker-controlled index in the same struct.

Read sge_offset once with READ_ONCE() and bound it (and the payload
that follows it) by qp->sq.max_inline before indexing, so the value
that is validated is the value that is used.

Fixes: 8700e3e7c485 ("Soft RoCE driver")
Cc: stable@vger.kernel.org
Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
Assisted-by: LLM
---
Notes (not part of the commit):
Reproduced on 7.3-rc4 as uid 1000: "BUG: unable to handle page fault ...
memcpy+0xc/0x30" from rxe_requester, 4/4. Present unchanged in mainline
551c722f4080 (2026-09-29) and rdma for-next. Compile-tested (KASAN+RDMA_RXE),
not runtime-tested. Found through manual review; per security-bugs.rst this is
public and a reproducer can be shared on request.

v2: the WQE lives in the mmap'd ring, so read dma.sge_offset once with
READ_ONCE() into a local and validate/index that local, closing the TOCTOU
noted in automated review (v1 re-read the field after the bounds check).
Dropped security@kernel.org Cc.

 drivers/infiniband/sw/rxe/rxe_req.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c
index 24f5c044363f..06e24d818075 100644
--- a/drivers/infiniband/sw/rxe/rxe_req.c
+++ b/drivers/infiniband/sw/rxe/rxe_req.c
@@ -510,7 +510,14 @@ static int finish_packet(struct rxe_qp *qp, struct rxe_av *av,

 	if (pkt->mask & RXE_WRITE_OR_SEND_MASK) {
 		if (wqe->wr.send_flags & IB_SEND_INLINE) {
-			u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset];
+			u32 sge_offset = READ_ONCE(wqe->dma.sge_offset);
+			u8 *tmp;
+
+			if (unlikely(sge_offset > (u32)qp->sq.max_inline ||
+				     payload > (u32)qp->sq.max_inline - sge_offset))
+				return -EINVAL;
+
+			tmp = &wqe->dma.inline_data[sge_offset];

 			memcpy(payload_addr(pkt), tmp, payload);

--
2.43.0

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

* Re: [PATCH v2] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]
  2026-10-01 15:24 ` [PATCH v2] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[] Youngsung Ahn
@ 2026-10-01 16:15   ` Leon Romanovsky
  2026-10-15 13:59   ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2026-10-01 16:15 UTC (permalink / raw)
  To: Youngsung Ahn; +Cc: Zhu Yanjun, linux-rdma, stable

On Fri, Oct 02, 2026 at 12:24:33AM +0900, Youngsung Ahn wrote:
> For a user QP, rxe_post_send() takes the qp->is_user branch and
> never runs init_send_wqe(), so
> dma.length/resid/num_sge/cur_sge/sge_offset all come straight from
> the mmap'd SQ ring. In the inline send path finish_packet() uses
> sge_offset directly as an index:
> 
> 	u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset];
> 	memcpy(payload_addr(pkt), tmp, payload);
> 
> inline_data is a flex array whose capacity is qp->sq.max_inline, but
> sge_offset is a u32 from user space, so the source pointer is
> displaced arbitrarily past the WQE and the memcpy reads out of
> bounds.
> commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]")
> added num_sge/cur_sge checks on the send path but not sge_offset, the
> third attacker-controlled index in the same struct.
> 
> Read sge_offset once with READ_ONCE() and bound it (and the payload
> that follows it) by qp->sq.max_inline before indexing, so the value
> that is validated is the value that is used.
> 
> Fixes: 8700e3e7c485 ("Soft RoCE driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
> Assisted-by: LLM
> ---
> Notes (not part of the commit):
> Reproduced on 7.3-rc4 as uid 1000: "BUG: unable to handle page fault ...
> memcpy+0xc/0x30" from rxe_requester, 4/4. Present unchanged in mainline
> 551c722f4080 (2026-09-29) and rdma for-next. Compile-tested (KASAN+RDMA_RXE),
> not runtime-tested. Found through manual review; per security-bugs.rst this is
> public and a reproducer can be shared on request.
> 
> v2: the WQE lives in the mmap'd ring, so read dma.sge_offset once with
> READ_ONCE() into a local and validate/index that local, closing the TOCTOU
> noted in automated review (v1 re-read the field after the bounds check).
> Dropped security@kernel.org Cc.
> 
>  drivers/infiniband/sw/rxe/rxe_req.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

Please do not send patches as replies to previous versions. Send them as
standalone messages.

Thanks

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

* Re: [PATCH v2] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]
  2026-10-01 15:24 ` [PATCH v2] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[] Youngsung Ahn
  2026-10-01 16:15   ` Leon Romanovsky
@ 2026-10-15 13:59   ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2026-10-15 13:59 UTC (permalink / raw)
  To: Zhu Yanjun, Youngsung Ahn; +Cc: linux-rdma, stable


On Fri, 02 Oct 2026 00:24:33 +0900, Youngsung Ahn wrote:
> For a user QP, rxe_post_send() takes the qp->is_user branch and
> never runs init_send_wqe(), so
> dma.length/resid/num_sge/cur_sge/sge_offset all come straight from
> the mmap'd SQ ring. In the inline send path finish_packet() uses
> sge_offset directly as an index:
> 
> 	u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset];
> 	memcpy(payload_addr(pkt), tmp, payload);
> 
> [...]

Applied, thanks!

[1/1] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]
      https://git.kernel.org/rdma/rdma/c/47a9c0338f2e0d

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>


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

end of thread, other threads:[~2026-10-15 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260930182216.2510953-1-ays511.kr@gmail.com>
2026-10-01 15:24 ` [PATCH v2] RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[] Youngsung Ahn
2026-10-01 16:15   ` Leon Romanovsky
2026-10-15 13:59   ` Leon Romanovsky

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