Skip to contentSkip to conversation

RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]

PATCH Superseded Youngsung Ahn 3 participants 6 messages Sep 30 – Oct 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]

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.

Bound sge_offset (and the payload that follows it) by qp->sq.max_inline before the copy.

Fixes 8700e3e7c485 ("Soft RoCE driver")

---
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.

 drivers/infiniband/sw/rxe/rxe_req.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_req.c +8 -1
index 24f5c044363f..06e24d818075 100644
@@ -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];
+			u8 *tmp;
+
+			if (unlikely(wqe->dma.sge_offset > (u32)qp->sq.max_inline ||
+				     payload > (u32)qp->sq.max_inline -
+					       wqe->dma.sge_offset))
+				return -EINVAL;
+
+			tmp = &wqe->dma.inline_data[wqe->dma.sge_offset];
 
 			memcpy(payload_addr(pkt), tmp, payload);
 

--
2.43.0

#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] rdma/rxe: TOCTOU bypass of sge_offset bounds check in finish_packet() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rdma/rxe: TOCTOU bypass of sge_offset bounds check in finish_packet() --

commit cb139c29341b6f7fcb85c3b737c416392d13b68f
Author: Youngsung Ahn <[email protected]>
Subject: RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]

This commit aims to fix an out-of-bounds read by bounding sge_offset against qp->sq.max_inline before copying inline data from the mmap'd send queue.

Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_req.c +0 -0
index 53f7c1e7fe55b..887bceed6b5d1 100644

drivers/infiniband/sw/rxe/rxe_req.c static int finish_packet(struct rxe_qp *qp, struct rxe_av *av, · line 518

Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_req.c +6 -1
@@ -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];
+			u8 *tmp;
+
+			if (unlikely(wqe->dma.sge_offset > (u32)qp->sq.max_inline ||
+				     payload > (u32)qp->sq.max_inline -
+					       wqe->dma.sge_offset))
+				return -EINVAL;

[Severity: High]
Since the send queue is mapped into user space, can a concurrent modification to wqe->dma.sge_offset bypass this check?

It looks like the value is read multiple times directly from shared memory. Could an attacker swap a valid offset with an invalid one immediately after the bounds check succeeds?

drivers/infiniband/sw/rxe/rxe_req.c static int finish_packet(struct rxe_qp *qp, struct rxe_av *av, · line 520

Quoted 2 lines
drivers/infiniband/sw/rxe/rxe_req.c +2 -0
+
+			tmp = &wqe->dma.inline_data[wqe->dma.sge_offset];

[Severity: High]
Does this setup an out-of-bounds pointer for the subsequent memcpy if wqe->dma.sge_offset is modified after the validation above?

Would caching wqe->dma.sge_offset in a local variable via READ_ONCE() prevent this race?

Quoted 3 lines
drivers/infiniband/sw/rxe/rxe_req.c +0 -0
 			memcpy(payload_addr(pkt), tmp, payload);
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v2 1/1 RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]

In reply to Youngsung Ahn

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")
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 [email protected] Cc.

 drivers/infiniband/sw/rxe/rxe_req.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_req.c +8 -1
index 24f5c044363f..06e24d818075 100644
@@ -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

#3 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines

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.

Quoted 7 lines

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")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw
In reply to Youngsung Ahn
Quoted 33 lines · Youngsung Ahn

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")
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.

Quoted 7 lines

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 [email protected] 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

#5 lore raw
In reply to Youngsung Ahn
Quoted 10 lines · Youngsung Ahn

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,

Signature · 1 line
Leon Romanovsky <[email protected]>