Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Tymbark7372 <tymbark7372@proton.me>
To: linux-rdma@vger.kernel.org
Cc: zyjzyj2000@gmail.com, jgg@nvidia.com, leonro@nvidia.com,
	stable@vger.kernel.org, Tymbark7372 <tymbark7372@proton.me>
Subject: [PATCH 3/4] RDMA/rxe: Fix u64 iova+resid overflow in duplicate_request
Date: Thu, 21 May 2026 19:44:15 +0000	[thread overview]
Message-ID: <20260521194402.811-4-tymbark7372@proton.me> (raw)
In-Reply-To: <20260521194402.811-1-tymbark7372@proton.me>

In the duplicate-READ handling of duplicate_request(), the third
clause of the bound check computes (iova + resid) and compares it
with (res->read.va_org + res->read.length).  iova is u64, resid is
u32 promoted to u64; the addition wraps modulo 2^64.  An attacker
setting reth_va = 0xFFFFFFFFFFFFFC00 and reth_len = 0x400 causes the
left-hand sum to wrap to 0 while the right-hand sum stays small, so
the check passes and res->read.va is later set to the wrap address on
replay.

Downstream of either bound check site in rxe_resp.c, read_reply
calls rxe_mr_copy() with the wrap iova, which re-traverses
mr_check_range() and rxe_mr_iova_to_index(), and rxe_mr_copy_xarray()
OOB-derefs page_info[huge_idx].  The primitive is the same as patch
1 of this series, reached via the RDMA_READ path on a duplicate
(retransmitted) request.

Use check_add_overflow() on both sides of the comparison.

Reproduced on v7.1.0-rc3 + KASAN with a single
ibv_post_send(IBV_WR_RDMA_READ) followed by a retransmit of the
identical packet, with the wrap iova above.  WARN at
rxe_mr_iova_to_index+0x135 followed by page-fault Oops in
rxe_mr_copy+0x20d on the READ path (rxe_receiver+0x3c70, distinct
from the WRITE offset rxe_receiver+0x6aa8 that the patch 1 trigger
reaches).

Fixes: 8700e3e7c485 ("Soft RoCE driver")
Cc: stable@vger.kernel.org # v4.8+
Reported-by: Tymbark7372 <tymbark7372@proton.me>
Signed-off-by: Tymbark7372 <tymbark7372@proton.me>
Assisted-by: Claude:claude-opus-4-7
---
 drivers/infiniband/sw/rxe/rxe_resp.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c
--- a/drivers/infiniband/sw/rxe/rxe_resp.c
+++ b/drivers/infiniband/sw/rxe/rxe_resp.c
@@ -1356,11 +1356,16 @@ static enum resp_states duplicate_request(struct rxe_qp *qp,
 			 */
 			u64 iova = reth_va(pkt);
 			u32 resid = reth_len(pkt);
+			u64 va_end_orig, va_end_new;

-			if (iova < res->read.va_org ||
+			if (check_add_overflow(res->read.va_org,
+					       (u64)res->read.length,
+					       &va_end_orig) ||
+			    check_add_overflow(iova, (u64)resid,
+					       &va_end_new) ||
+			    iova < res->read.va_org ||
 			    resid > res->read.length ||
-			    (iova + resid) > (res->read.va_org +
-					      res->read.length)) {
+			    va_end_new > va_end_orig) {
 				rc = RESPST_CLEANUP;
 				goto out;
 			}
--
2.43.0


  parent reply	other threads:[~2026-05-21 19:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 19:44 [PATCH 0/4] RDMA/rxe: Fix u64 iova-overflow family in MR/ODP/RESP/MW paths Tymbark7372
2026-05-21 19:44 ` [PATCH 1/4] RDMA/rxe: Fix u64 iova+length overflow in mr_check_range Tymbark7372
2026-05-22  4:44   ` Greg KH
2026-05-21 19:44 ` [PATCH 2/4] RDMA/rxe: Fix u64 iova+length overflow in rxe_check_pagefault Tymbark7372
2026-05-21 19:44 ` Tymbark7372 [this message]
2026-05-21 19:44 ` [PATCH 4/4] RDMA/rxe: Fix u64 addr+length overflow in rxe_check_bind_mw Tymbark7372
2026-05-22  2:54 ` [PATCH 0/4] RDMA/rxe: Fix u64 iova-overflow family in MR/ODP/RESP/MW paths Zhu Yanjun
2026-05-25 11:15   ` Tymbark7372
2026-05-25 20:54     ` Zhu Yanjun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260521194402.811-4-tymbark7372@proton.me \
    --to=tymbark7372@proton.me \
    --cc=jgg@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zyjzyj2000@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox