* [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
@ 2026-09-30 18:01 Youngsung Ahn
2026-09-30 18:11 ` sashiko-bot
2026-10-01 15:23 ` [PATCH v2] " Youngsung Ahn
0 siblings, 2 replies; 9+ messages in thread
From: Youngsung Ahn @ 2026-09-30 18:01 UTC (permalink / raw)
To: zyjzyj2000; +Cc: linux-rdma, security
A user QP's receive queue is an mmap'd ring: the user provider
writes the WQEs and post_recv does not touch them, so every field of
struct rxe_recv_wqe is attacker controlled. When the responder takes
a WQE it validates only dma.num_sge (rxe_get_recv_wqe() /
get_srq_wqe()); dma.cur_sge, dma.sge_offset and dma.resid are copied
into qp->resp.srq_wqe unchecked.
copy_data() then uses cur_sge as an index immediately --
struct rxe_sge *sge = &dma->sge[dma->cur_sge];
-- and dereferences it (sge->length) before the in-loop
"dma->cur_sge >= dma->num_sge" test, which only runs after the first
sge++. cur_sge is a u32, so this reads far out of bounds of the
RXE_MAX_SGE-entry dma->sge[] embedded in the kmalloc-2k struct
rxe_qp: an information leak (the out-of-bounds sge->length is
recoverable through the work-completion status) and a DoS. The send
queue already got this check in
commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]");
the receive path did not.
Reject an out-of-range cur_sge in copy_data() before the first sge
dereference. This also covers the send retry path and is harmless to
the kernel ULP path, which always sets cur_sge = 0.
Fixes: 8700e3e7c485 ("Soft RoCE driver")
Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
---
Notes (not part of the commit):
Reproduced on a KASAN x86-64 build of 7.3-rc4 as uid 1000 (uverbs0 is 0666
after a one-time "rdma link add"), cross-checked via the CQE-status bit
oracle. 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_mr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index 71d9ea477289..b9aff32fffad 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -437,6 +437,11 @@ int copy_data(
goto err2;
}
+ if (unlikely(dma->cur_sge >= dma->num_sge)) {
+ err = -EINVAL;
+ goto err2;
+ }
+
if (sge->length && (offset < sge->length)) {
mr = lookup_mr(pd, access, sge->lkey, RXE_LOOKUP_LOCAL);
if (!mr) {
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
2026-09-30 18:01 [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[] Youngsung Ahn
@ 2026-09-30 18:11 ` sashiko-bot
2026-10-01 15:23 ` [PATCH v2] " Youngsung Ahn
1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-09-30 18:11 UTC (permalink / raw)
To: Youngsung Ahn; +Cc: linux-rdma
> A user QP's receive queue is an mmap'd ring: the user provider
> writes the WQEs and post_recv does not touch them, so every field of
> struct rxe_recv_wqe is attacker controlled. When the responder takes
> a WQE it validates only dma.num_sge (rxe_get_recv_wqe() /
> get_srq_wqe()); dma.cur_sge, dma.sge_offset and dma.resid are copied
> into qp->resp.srq_wqe unchecked.
>
> copy_data() then uses cur_sge as an index immediately --
> struct rxe_sge *sge = &dma->sge[dma->cur_sge];
> -- and dereferences it (sge->length) before the in-loop
> "dma->cur_sge >= dma->num_sge" test, which only runs after the first
> sge++. cur_sge is a u32, so this reads far out of bounds of the
> RXE_MAX_SGE-entry dma->sge[] embedded in the kmalloc-2k struct
> rxe_qp: an information leak (the out-of-bounds sge->length is
> recoverable through the work-completion status) and a DoS. The send
> queue already got this check in
> commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]");
> the receive path did not.
>
> Reject an out-of-range cur_sge in copy_data() before the first sge
> dereference. This also covers the send retry path and is harmless to
> the kernel ULP path, which always sets cur_sge = 0.
>
> Fixes: 8700e3e7c485 ("Soft RoCE driver")
> Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260930180119.2497360-1-ays511.kr@gmail.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
2026-09-30 18:01 [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[] Youngsung Ahn
2026-09-30 18:11 ` sashiko-bot
@ 2026-10-01 15:23 ` Youngsung Ahn
2026-10-01 15:42 ` sashiko-bot
1 sibling, 1 reply; 9+ messages in thread
From: Youngsung Ahn @ 2026-10-01 15:23 UTC (permalink / raw)
To: Zhu Yanjun; +Cc: linux-rdma, Youngsung Ahn, stable
A user QP's receive queue is an mmap'd ring: the user provider
writes the WQEs and post_recv does not touch them, so every field of
struct rxe_recv_wqe is attacker controlled. When the responder takes
a WQE it validates only dma.num_sge (rxe_get_recv_wqe() /
get_srq_wqe()); dma.cur_sge, dma.sge_offset and dma.resid are copied
into qp->resp.srq_wqe unchecked.
copy_data() then uses cur_sge as an index immediately --
struct rxe_sge *sge = &dma->sge[dma->cur_sge];
-- and dereferences it (sge->length) before the in-loop
"dma->cur_sge >= dma->num_sge" test, which only runs after the first
sge++. cur_sge is a u32, so this reads far out of bounds of the
RXE_MAX_SGE-entry dma->sge[] embedded in the kmalloc-2k struct
rxe_qp: an information leak (the out-of-bounds sge->length is
recoverable through the work-completion status) and a DoS. The send
queue already got this check in
commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]");
the receive path did not.
Reject an out-of-range cur_sge in copy_data() before the first sge
dereference. This also covers the send retry path and is harmless to
the kernel ULP path, which always sets cur_sge = 0.
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 a KASAN x86-64 build of 7.3-rc4 as uid 1000 (uverbs0 is 0666
after a one-time "rdma link add"), cross-checked via the CQE-status bit
oracle. Present unchanged in mainline 551c722f4080 (2026-09-29) and rdma
for-next. Compile-tested (KASAN+RDMA_RXE), not runtime-tested. Per
security-bugs.rst this is public and a reproducer can be shared on request.
The responder works on the kernel-side copy in qp->resp.srq_wqe, so there is
no TOCTOU on cur_sge here.
v2: no code change. Fixed the author/Signed-off-by mismatch (v1 went out via
Gmail with the display name "AYS"), resent as plain text via git send-email,
and added Cc: stable@vger.kernel.org and Assisted-by: LLM per Greg KH's review.
drivers/infiniband/sw/rxe/rxe_mr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index 71d9ea477289..b9aff32fffad 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -437,6 +437,11 @@ int copy_data(
goto err2;
}
+ if (unlikely(dma->cur_sge >= dma->num_sge)) {
+ err = -EINVAL;
+ goto err2;
+ }
+
if (sge->length && (offset < sge->length)) {
mr = lookup_mr(pd, access, sge->lkey, RXE_LOOKUP_LOCAL);
if (!mr) {
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
2026-10-01 15:23 ` [PATCH v2] " Youngsung Ahn
@ 2026-10-01 15:42 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-10-01 15:42 UTC (permalink / raw)
To: Youngsung Ahn; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] RDMA/rxe: double-fetch TOCTOU vulnerability in copy_data() bounds check
--
commit 2fd3d60fe5490f46cfcd1b0614c53c62687fc767
Author: Youngsung Ahn <ays511.kr@gmail.com>
RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
This commit adds bounds validation for cur_sge in copy_data() on the receive
path before the scatter/gather array is accessed. It intends to reject an
out-of-range cur_sge to prevent denial of service or information leaks.
> diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
> index 2afda5154dfb9..0c510bb7ae2a7 100644
> --- a/drivers/infiniband/sw/rxe/rxe_mr.c
> +++ b/drivers/infiniband/sw/rxe/rxe_mr.c
> @@ -436,6 +436,11 @@ int copy_data(
> goto err2;
> }
>
> + if (unlikely(dma->cur_sge >= dma->num_sge)) {
[Severity: High]
Since dma can point directly into an attacker-controlled mmap'd ring buffer,
could this introduce a double-fetch vulnerability?
For example, on the send path, a WQE is retrieved without a kernel copy and
passed along:
rxe_requester()
finish_packet()
copy_data(..., &wqe->dma, ...)
Earlier in copy_data(), sge is initialized by fetching dma->cur_sge:
struct rxe_sge *sge = &dma->sge[dma->cur_sge];
Because the check added here lacks READ_ONCE(), the compiler could fetch
dma->cur_sge twice from shared memory.
A malicious thread might race to provide an out-of-bounds value for the first
fetch, followed by a valid value for this second fetch. This would bypass the
check and result in an out-of-bounds dereference when sge->length is evaluated
shortly after.
Would caching dma->cur_sge locally with READ_ONCE() prevent this?
> + err = -EINVAL;
> + goto err2;
> + }
> +
> if (sge->length && (offset < sge->length)) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261001152345.3259024-1-ays511.kr@gmail.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <CAPAqSgYT9torsoAh_UexRewz-uPV9QNzOg1v3TPFxykQSaMJGA@mail.gmail.com>]
* Re: [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
[not found] <CAPAqSgYT9torsoAh_UexRewz-uPV9QNzOg1v3TPFxykQSaMJGA@mail.gmail.com>
@ 2026-09-30 19:21 ` Willy Tarreau
0 siblings, 0 replies; 9+ messages in thread
From: Willy Tarreau @ 2026-09-30 19:21 UTC (permalink / raw)
To: AYS; +Cc: zyjzyj2000, linux-rdma, security
Hello,
On Wed, Sep 30, 2026 at 11:02:13PM +0900, AYS wrote:
(...)
> diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c
> b/drivers/infiniband/sw/rxe/rxe_mr.c
> index 71d9ea477289..b9aff32fffad 100644
> --- a/drivers/infiniband/sw/rxe/rxe_mr.c
> +++ b/drivers/infiniband/sw/rxe/rxe_mr.c
> @@ -437,6 +437,11 @@ int copy_data(
> goto err2;
> }
>
> + if (unlikely(dma->cur_sge >= dma->num_sge)) {
> + err = -EINVAL;
> + goto err2;
> + }
> +
> if (sge->length && (offset < sge->length)) {
> mr = lookup_mr(pd, access, sge->lkey, RXE_LOOKUP_LOCAL);
> if (!mr) {
All your messages arrive mangled. Please fix your email clients after
consulting Documentation/process/email-clients.rst. Also as a general
rule it's not a good idea to send a flood of messages without verifying
that the setup is OK, because now everyone will delete your whole series
without checking further. You'd rather wait at least a day before
resending to avoid your second series being trashed by accident in the
same batch. Also don't forget to mark them v2.
Willy
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
@ 2026-09-30 15:15 AYS
2026-09-30 15:34 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: AYS @ 2026-09-30 15:15 UTC (permalink / raw)
To: zyjzyj2000; +Cc: linux-rdma, security
A user QP's receive queue is an mmap'd ring: the user provider writes the
WQEs and post_recv does not touch them, so every field of struct
rxe_recv_wqe is attacker controlled. When the responder takes a WQE it
validates only dma.num_sge (rxe_get_recv_wqe()/get_srq_wqe()); dma.cur_sge,
dma.sge_offset and dma.resid are copied into qp->resp.srq_wqe unchecked.
copy_data() then uses cur_sge as an index immediately --
struct rxe_sge *sge = &dma->sge[dma->cur_sge];
-- and dereferences it (sge->length) before the in-loop
"dma->cur_sge >= dma->num_sge" test, which only runs after the first sge++.
cur_sge is a u32, so this reads far out of bounds of the RXE_MAX_SGE-entry
dma->sge[] embedded in the kmalloc-2k struct rxe_qp: an information leak (the
out-of-bounds sge->length is recoverable through the work-completion status)
and a DoS. The send queue already got this check in commit 126c757e4cd4; the
receive path did not.
Reject an out-of-range cur_sge in copy_data() before the first sge
dereference. This also covers the send retry path and is harmless to the
kernel ULP path, which always sets cur_sge = 0.
Fixes: 8700e3e7c485 ("Soft RoCE driver")
Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
---
Notes (not part of the commit):
Reproduced on a KASAN x86-64 build of 7.3-rc4 as uid 1000 (uverbs0 is 0666
after a one-time "rdma link add"), cross-checked via the CQE-status bit
oracle. 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_mr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c
b/drivers/infiniband/sw/rxe/rxe_mr.c
index 71d9ea477289..b9aff32fffad 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -437,6 +437,11 @@ int copy_data(
goto err2;
}
+ if (unlikely(dma->cur_sge >= dma->num_sge)) {
+ err = -EINVAL;
+ goto err2;
+ }
+
if (sge->length && (offset < sge->length)) {
mr = lookup_mr(pd, access, sge->lkey, RXE_LOOKUP_LOCAL);
if (!mr) {
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
2026-09-30 15:15 AYS
@ 2026-09-30 15:34 ` Greg KH
2026-10-01 16:07 ` Leon Romanovsky
2026-10-01 16:44 ` Zhu Yanjun
0 siblings, 2 replies; 9+ messages in thread
From: Greg KH @ 2026-09-30 15:34 UTC (permalink / raw)
To: AYS; +Cc: zyjzyj2000, linux-rdma, security
On Thu, Oct 01, 2026 at 12:15:52AM +0900, AYS wrote:
> A user QP's receive queue is an mmap'd ring: the user provider writes the
> WQEs and post_recv does not touch them, so every field of struct
> rxe_recv_wqe is attacker controlled. When the responder takes a WQE it
> validates only dma.num_sge (rxe_get_recv_wqe()/get_srq_wqe()); dma.cur_sge,
> dma.sge_offset and dma.resid are copied into qp->resp.srq_wqe unchecked.
>
> copy_data() then uses cur_sge as an index immediately --
> struct rxe_sge *sge = &dma->sge[dma->cur_sge];
> -- and dereferences it (sge->length) before the in-loop
> "dma->cur_sge >= dma->num_sge" test, which only runs after the first sge++.
> cur_sge is a u32, so this reads far out of bounds of the RXE_MAX_SGE-entry
> dma->sge[] embedded in the kmalloc-2k struct rxe_qp: an information leak (the
> out-of-bounds sge->length is recoverable through the work-completion status)
> and a DoS. The send queue already got this check in commit 126c757e4cd4; the
> receive path did not.
>
> Reject an out-of-range cur_sge in copy_data() before the first sge
> dereference. This also covers the send retry path and is harmless to the
> kernel ULP path, which always sets cur_sge = 0.
>
> Fixes: 8700e3e7c485 ("Soft RoCE driver")
> Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
Does not match the "From:" line :(
No cc: stable?
No Assisted-by: line?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
2026-09-30 15:34 ` Greg KH
@ 2026-10-01 16:07 ` Leon Romanovsky
2026-10-01 16:44 ` Zhu Yanjun
1 sibling, 0 replies; 9+ messages in thread
From: Leon Romanovsky @ 2026-10-01 16:07 UTC (permalink / raw)
To: Greg KH; +Cc: AYS, zyjzyj2000, linux-rdma, security
On Wed, Sep 30, 2026 at 05:34:55PM +0200, Greg KH wrote:
> On Thu, Oct 01, 2026 at 12:15:52AM +0900, AYS wrote:
> > A user QP's receive queue is an mmap'd ring: the user provider writes the
> > WQEs and post_recv does not touch them, so every field of struct
> > rxe_recv_wqe is attacker controlled. When the responder takes a WQE it
> > validates only dma.num_sge (rxe_get_recv_wqe()/get_srq_wqe()); dma.cur_sge,
> > dma.sge_offset and dma.resid are copied into qp->resp.srq_wqe unchecked.
> >
> > copy_data() then uses cur_sge as an index immediately --
> > struct rxe_sge *sge = &dma->sge[dma->cur_sge];
> > -- and dereferences it (sge->length) before the in-loop
> > "dma->cur_sge >= dma->num_sge" test, which only runs after the first sge++.
> > cur_sge is a u32, so this reads far out of bounds of the RXE_MAX_SGE-entry
> > dma->sge[] embedded in the kmalloc-2k struct rxe_qp: an information leak (the
> > out-of-bounds sge->length is recoverable through the work-completion status)
> > and a DoS. The send queue already got this check in commit 126c757e4cd4; the
> > receive path did not.
> >
> > Reject an out-of-range cur_sge in copy_data() before the first sge
> > dereference. This also covers the send retry path and is harmless to the
> > kernel ULP path, which always sets cur_sge = 0.
> >
> > Fixes: 8700e3e7c485 ("Soft RoCE driver")
> > Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
>
> Does not match the "From:" line :(
>
> No cc: stable?
No need to CC stable@ on RXE patches; I will remove it when applying them anyway.
Nothing urgent here.
Thanks
>
> No Assisted-by: line?
>
> thanks,
>
> greg k-h
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[]
2026-09-30 15:34 ` Greg KH
2026-10-01 16:07 ` Leon Romanovsky
@ 2026-10-01 16:44 ` Zhu Yanjun
1 sibling, 0 replies; 9+ messages in thread
From: Zhu Yanjun @ 2026-10-01 16:44 UTC (permalink / raw)
To: Greg KH, AYS; +Cc: zyjzyj2000, linux-rdma, security
在 2026/9/30 8:34, Greg KH 写道:
> On Thu, Oct 01, 2026 at 12:15:52AM +0900, AYS wrote:
>> A user QP's receive queue is an mmap'd ring: the user provider writes the
>> WQEs and post_recv does not touch them, so every field of struct
>> rxe_recv_wqe is attacker controlled. When the responder takes a WQE it
>> validates only dma.num_sge (rxe_get_recv_wqe()/get_srq_wqe()); dma.cur_sge,
>> dma.sge_offset and dma.resid are copied into qp->resp.srq_wqe unchecked.
>>
>> copy_data() then uses cur_sge as an index immediately --
>> struct rxe_sge *sge = &dma->sge[dma->cur_sge];
>> -- and dereferences it (sge->length) before the in-loop
>> "dma->cur_sge >= dma->num_sge" test, which only runs after the first sge++.
>> cur_sge is a u32, so this reads far out of bounds of the RXE_MAX_SGE-entry
>> dma->sge[] embedded in the kmalloc-2k struct rxe_qp: an information leak (the
>> out-of-bounds sge->length is recoverable through the work-completion status)
>> and a DoS. The send queue already got this check in commit 126c757e4cd4; the
>> receive path did not.
>>
>> Reject an out-of-range cur_sge in copy_data() before the first sge
>> dereference. This also covers the send retry path and is harmless to the
>> kernel ULP path, which always sets cur_sge = 0.
>>
>> Fixes: 8700e3e7c485 ("Soft RoCE driver")
>> Signed-off-by: Youngsung Ahn <ays511.kr@gmail.com>
>
> Does not match the "From:" line :(
>
> No cc: stable?
>
> No Assisted-by: line?
In v2, this Assisted-by tag has been added.
Yanjun Zhu>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-10-01 16:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30 18:01 [PATCH] RDMA/rxe: validate cur_sge on the receive path before indexing dma->sge[] Youngsung Ahn
2026-09-30 18:11 ` sashiko-bot
2026-10-01 15:23 ` [PATCH v2] " Youngsung Ahn
2026-10-01 15:42 ` sashiko-bot
[not found] <CAPAqSgYT9torsoAh_UexRewz-uPV9QNzOg1v3TPFxykQSaMJGA@mail.gmail.com>
2026-09-30 19:21 ` [PATCH] " Willy Tarreau
-- strict thread matches above, loose matches on Subject: below --
2026-09-30 15:15 AYS
2026-09-30 15:34 ` Greg KH
2026-10-01 16:07 ` Leon Romanovsky
2026-10-01 16:44 ` Zhu Yanjun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox