* [PATCH] RDMA/rxe: reject ODP accesses that wrap the iova space
@ 2026-11-20 6:00 Yiran Qiu
2026-11-20 6:10 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yiran Qiu @ 2026-11-20 6:00 UTC (permalink / raw)
To: zyjzyj2000, jgg, leon; +Cc: linux-rdma, linux-kernel, Yiran Qiu, stable
rxe_check_pagefault() decides whether an ODP access needs a page fault
by walking its pages, and bounds the page index against the umem inside
that walk. When iova + length wraps past 2^64 the loop does not run, so
neither that bound nor the HMM_PFN_VALID and HMM_PFN_WRITE checks apply,
and no fault is taken. __rxe_odp_mr_copy() and the atomic write and
flush helpers then index map.pfn_list[] with (iova - ib_umem_start()) >>
page_shift, which the registrant controls: ib_uverbs_reg_mr() only
requires the MR's iova to share the page offset of the user address. The
entry read past pfn_list[] goes to hmm_pfn_to_page(), and that page is
copied to or from the peer.
rxe_check_pagefault() also keeps the index in an int, so an index of
2^32 or more can be truncated to a value that passes the bound, while
the flush and atomic write helpers use the full unsigned long.
Reject a wrapping range in rxe_odp_map_range_and_lock(), before the
fault path, whose umem range check wraps the same way, and keep the
index in an unsigned long.
Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix
and this changelog were also drafted with LLM assistance. Reproduced on
an unmodified KASAN build of mainline by an unprivileged user with a
self-connected rxe QP. An RDMA READ at the end of a two-page ODP MR
whose iova range ends at 2^64:
BUG: KASAN: slab-out-of-bounds in rxe_odp_mr_copy+0x35f/0x410
Read of size 8 at addr ffff8881037a2210 by task kworker/u16:0/13
The buggy address is located 0 bytes to the right of
allocated 16-byte region [ffff8881037a2200, ffff8881037a2210)
Oops: general protection fault, maybe for address 0xffff888103d0c04a: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:memcpy+0xc/0x30
An ATOMIC WRITE to an MR whose iova is 2^44 above the umem start:
BUG: unable to handle page fault for address: ffffed11202b3194
RIP: 0010:rxe_odp_do_atomic_write+0x131/0x2f0
With this patch both are NAKed with no report, and an in-range READ and
ATOMIC WRITE return the same results as before. The wrap was not tried
on the flush path. The rdma-core v65.0 tests, ODP included, pass on rxe
with and without this patch.
Fixes: 2fae67ab63db ("RDMA/rxe: Add support for Send/Recv/Write/Read with ODP")
Cc: stable@vger.kernel.org # 6.15.x: 7797bbb0e86f: RDMA/rxe: bound the ODP page index against the umem in rxe_check_pagefault()
Signed-off-by: Yiran Qiu <eritque-arcus@ikuyo.dev>
---
Tested on mainline 4405c18c95d2 (v7.4-rc3+) in QEMU. Applies to
rdma.git for-rc and for-next.
This completes commit 7797bbb0e86f, whose bound sits in the loop that
a wrapping range skips; stable trees need that commit first.
Without KASAN, an RDMA READ or WRITE at the end of the range reads or
overwrites a physical page the registrant chooses. On a lab kernel with
CONFIG_RANDOMIZE_BASE=n this was taken from an unprivileged user to
uid 0; with KASLR the chain also needs an address leak. The rxe link
has to be created by an administrator; the trigger needs only the
uverbs device. A reproducer and the test logs are available on request.
drivers/infiniband/sw/rxe/rxe_odp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_odp.c b/drivers/infiniband/sw/rxe/rxe_odp.c
index 9d27244f89bc..2ab64f128e57 100644
--- a/drivers/infiniband/sw/rxe/rxe_odp.c
+++ b/drivers/infiniband/sw/rxe/rxe_odp.c
@@ -125,7 +125,7 @@ static inline bool rxe_check_pagefault(struct ib_umem_odp *umem_odp, u64 iova,
bool need_fault = false;
u64 access = HMM_PFN_VALID;
u64 addr;
- int idx;
+ unsigned long idx;
if (write)
access |= HMM_PFN_WRITE;
@@ -171,6 +171,9 @@ static int rxe_odp_map_range_and_lock(struct rxe_mr *mr, u64 iova, int length, u
if (unlikely(length < 1))
return -EINVAL;
+ if (unlikely(iova + length < iova))
+ return -EFAULT;
+
mutex_lock(&umem_odp->umem_mutex);
need_fault = rxe_check_pagefault(umem_odp, iova, length, write);
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] RDMA/rxe: reject ODP accesses that wrap the iova space
2026-11-20 6:00 [PATCH] RDMA/rxe: reject ODP accesses that wrap the iova space Yiran Qiu
@ 2026-11-20 6:10 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-20 6:10 UTC (permalink / raw)
To: Yiran Qiu; +Cc: linux-rdma
> rxe_check_pagefault() decides whether an ODP access needs a page fault
> by walking its pages, and bounds the page index against the umem inside
> that walk. When iova + length wraps past 2^64 the loop does not run, so
> neither that bound nor the HMM_PFN_VALID and HMM_PFN_WRITE checks apply,
> and no fault is taken. __rxe_odp_mr_copy() and the atomic write and
> flush helpers then index map.pfn_list[] with (iova - ib_umem_start()) >>
> page_shift, which the registrant controls: ib_uverbs_reg_mr() only
> requires the MR's iova to share the page offset of the user address. The
> entry read past pfn_list[] goes to hmm_pfn_to_page(), and that page is
> copied to or from the peer.
>
> rxe_check_pagefault() also keeps the index in an int, so an index of
> 2^32 or more can be truncated to a value that passes the bound, while
> the flush and atomic write helpers use the full unsigned long.
>
> [ ... ]
> with and without this patch.
>
> Fixes: 2fae67ab63db ("RDMA/rxe: Add support for Send/Recv/Write/Read with ODP")
> Cc: stable@vger.kernel.org # 6.15.x: 7797bbb0e86f: RDMA/rxe: bound the ODP page index against the umem in rxe_check_pagefault()
> Signed-off-by: Yiran Qiu <eritque-arcus@ikuyo.dev>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120060000.302440-1-eritque-arcus@ikuyo.dev?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 6:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 6:00 [PATCH] RDMA/rxe: reject ODP accesses that wrap the iova space Yiran Qiu
2026-11-20 6:10 ` 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.