[PATCH v2 2/2] RDMA/srp: do not DMA-sync a receive IU past its mapped length

From: Yehyeong Lee

Date: Mon Oct 26 2026 - 01:22:09 EST


srp_recv_done() syncs the receive IU with ch->max_ti_iu_len, but the IU
was mapped with iu->size. Those are the same value only until the first
reconnect. srp_cm_rep_handler() takes ch->max_ti_iu_len from every
SRP_LOGIN_RSP while it allocates the receive ring only when there is none,
and srp_rport_reconnect() keeps the ring across a reconnect, so a target
that reports a larger max_ti_iu_len the second time around makes both
ib_dma_sync_single_for_cpu() and ib_dma_sync_single_for_device() run past
the end of the mapping, which breaks the DMA API rules.

The HCA itself cannot overrun the buffer, because srp_post_recv() posts
iu->size, so sync the length that was actually mapped.

Suggested-by: Bart Van Assche <bvanassche@xxxxxxx>
Fixes: aef9ec39c47f ("IB: Add SCSI RDMA Protocol (SRP) initiator")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Yehyeong Lee <yhlee@xxxxxxxxxxxxxxxxxx>
---
drivers/infiniband/ulp/srp/ib_srp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index a85d28b95306a..159d6b6aa93e3 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -2111,7 +2111,7 @@ static void srp_recv_done(struct ib_cq *cq, struct ib_wc *wc)
return;
}

- ib_dma_sync_single_for_cpu(dev, iu->dma, ch->max_ti_iu_len,
+ ib_dma_sync_single_for_cpu(dev, iu->dma, iu->size,
DMA_FROM_DEVICE);

opcode = *(u8 *) iu->buf;
@@ -2148,7 +2148,7 @@ static void srp_recv_done(struct ib_cq *cq, struct ib_wc *wc)
break;
}

- ib_dma_sync_single_for_device(dev, iu->dma, ch->max_ti_iu_len,
+ ib_dma_sync_single_for_device(dev, iu->dma, iu->size,
DMA_FROM_DEVICE);

res = srp_post_recv(ch, iu);