[PATCH 1/1] RDMA/srpt: Limit read data transfers to the command length

From: liuyong

Date: Mon Nov 09 2026 - 22:23:26 EST


SRPT builds RDMA contexts from the initiator's buffer descriptors before
parsing the CDB. For a READ underflow, target core reduces
cmd->data_length, but the prebuilt RDMA WRITE requests still cover the
full descriptor length. A backend such as rd_mcp fills only the shortened
command length, allowing the uninitialized tail to reach the initiator.

A remote initiator with access to the LUN can therefore read
uninitialized target kernel memory beyond the requested SCSI data,
potentially exposing sensitive data left from previous uses of those
pages.

For a READ underflow, limit the data SGEs in the RDMA WRITE chain to
cmd->data_length before posting it. Preserve memory registration and
invalidation requests, and retain zero-length RDMA WRITEs beyond the
limit so that work-request accounting and resource cleanup remain
unchanged.

The issue was discovered and fixed by Qihoo 360's Tulongfeng multi-agent
system.

Fixes: b99f8e4d7bcd ("IB/srpt: convert to the generic RDMA READ/WRITE API")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: liuyong <pkfxxxing@xxxxxxxxx>
---
drivers/infiniband/ulp/srpt/ib_srpt.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 43c3ff1ad..2f7857ef4 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -2913,6 +2913,26 @@ static void srpt_queue_response(struct se_cmd *cmd)
first_wr = rdma_rw_ctx_wrs(&ctx->rw, ch->qp,
ch->sport->port, NULL, first_wr);
}
+
+ if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
+ struct ib_send_wr *wr;
+ u32 data_len = cmd->data_length;
+
+ /* Keep MR operations and WR accounting unchanged. */
+ for (wr = first_wr; wr != &send_wr; wr = wr->next) {
+ int j;
+
+ if (wr->opcode != IB_WR_RDMA_WRITE)
+ continue;
+ for (j = 0; j < wr->num_sge && data_len; j++) {
+ struct ib_sge *sge = &wr->sg_list[j];
+
+ sge->length = min(sge->length, data_len);
+ data_len -= sge->length;
+ }
+ wr->num_sge = j;
+ }
+ }
}

if (state != SRPT_STATE_MGMT)