RDMA/rtrs-srv: Bound RDMA-Write length to chunk size in rdma_write_sg
Subsystems (3)
PATCH 1/1 RDMA/rtrs-srv: Bound RDMA-Write length to chunk size in rdma_write_sg
When the server answers an RTRS READ, rdma_write_sg() builds the source scatter/gather entry for the IB_WR_RDMA_WRITE that returns data to the peer. Its length is taken directly from the wire descriptor:
plist->length = le32_to_cpu(id->rd_msg->desc[0].len);
rd_msg points into the chunk buffer that the remote peer filled via RDMA-WRITE-WITH-IMM (rtrs_srv_rdma_done() -> process_io_req() -> process_read()), so desc[0].len is attacker-controlled and, before this change, was only rejected when zero. The source address is the fixed chunk start (dma_addr[msg_id]) and the source lkey is the PD-wide local_dma_lkey, which is not tied to the chunk's MR mapping, so the verbs layer does not constrain the transfer length to max_chunk_size. msg_id and off are bounded against queue_depth and max_chunk_size in rtrs_srv_rdma_done(), but desc[0].len is a separate field that was not checked against the chunk size.
A peer that advertises desc[0].len larger than max_chunk_size can make the posted RDMA write read past the chunk's mapped region. The resulting behaviour depends on the IOMMU configuration: with no IOMMU or in passthrough mode the read may extend into memory adjacent to the chunk and be returned to the peer, which can disclose host memory; with a translating IOMMU the out-of-range access is expected to fault and abort the connection. In either case the transfer exceeds what the protocol permits and is driven by a remote peer.
Reject a descriptor length above max_chunk_size, mirroring the existing off >= max_chunk_size bound in rtrs_srv_rdma_done(). Legitimate clients do not exceed it: the client sets desc[0].len to its MR length, which is capped at the negotiated max_io_size (max_chunk_size - MAX_HDR_SIZE).
--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +3 -2
@@ -225,8 +225,9 @@ static int rdma_write_sg(struct rtrs_srv_op *id)/* WR will fail with length error * if this is 0 */ -if (plist->length ==0 ) { -rtrs_err (s,"Invalid RDMA-Write sg list length 0\n" ); +if (plist->length ==0 || plist->length > max_chunk_size) { +rtrs_err (s,"Invalid RDMA-Write sg list length %u\n" , + plist->length);return -EINVAL ; }
---
base-commit: a48671671df5158a0b8e564cd509e04a090a941b
change-id: 20260612-master-7cbc156da1f8
Best regards,
Signature · 1 line
Zhenhao Wan <[email protected]>
Quoted 32 lines · Zhenhao Wan
When the server answers an RTRS READ,
rdma_write_sg()builds the source scatter/gather entry for theIB_WR_RDMA_WRITEthat returns data to the peer. Its length is taken directly from the wire descriptor:plist->length = le32_to_cpu(id->rd_msg->desc[0].len);
rd_msgpoints into the chunk buffer that the remote peer filled via RDMA-WRITE-WITH-IMM (rtrs_srv_rdma_done()->process_io_req()->process_read()), so desc[0].len is attacker-controlled and, before this change, was only rejected when zero. The source address is the fixed chunk start (dma_addr[msg_id]) and the source lkey is the PD-widelocal_dma_lkey, which is not tied to the chunk's MR mapping, so the verbs layer does not constrain the transfer length tomax_chunk_size.msg_idand off are bounded againstqueue_depthandmax_chunk_sizeinrtrs_srv_rdma_done(), but desc[0].len is a separate field that was not checked against the chunk size.A peer that advertises desc[0].len larger than
max_chunk_sizecan make the posted RDMA write read past the chunk's mapped region. The resulting behaviour depends on the IOMMU configuration: with no IOMMU or in passthrough mode the read may extend into memory adjacent to the chunk and be returned to the peer, which can disclose host memory; with a translating IOMMU the out-of-range access is expected to fault and abort the connection. In either case the transfer exceeds what the protocol permits and is driven by a remote peer.Reject a descriptor length above
max_chunk_size, mirroring the existing off >=max_chunk_sizebound inrtrs_srv_rdma_done(). Legitimate clients do not exceed it: the client sets desc[0].len to its MR length, which is capped at the negotiatedmax_io_size(max_chunk_size-MAX_HDR_SIZE).
Quoted 4 lines
Fixes 9cb837480424 ("RDMA/rtrs: server: main functionality")Reported-by Yuhao Jiang <[email protected]>Signed-off-by Zhenhao Wan <[email protected]>
Looks good.
Reviewed and tested.
Quoted 29 lines
--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-srv.c +3
-3@@ -225,8 +225,9 @@ static int rdma_write_sg(struct rtrs_srv_op *id)/* WR will fail with length error * if this is 0 */ -if (plist->length ==0 ) { -rtrs_err (s,"Invalid RDMA-Write sg list length 0\n" ); +if (plist->length ==0 || plist->length > max_chunk_size) { +rtrs_err (s,"Invalid RDMA-Write sg list length %u\n" , + plist->length);return -EINVAL ; } ---base-commit:
a48671671df5158a0b8e564cd509e04a090a941b
change-id: 20260612-master-7cbc156da1f8Best regards,
--
Zhenhao Wan <[email protected]>
Quoted 31 lines · Zhenhao Wan
When the server answers an RTRS READ,
rdma_write_sg()builds the source scatter/gather entry for theIB_WR_RDMA_WRITEthat returns data to the peer. Its length is taken directly from the wire descriptor:plist->length = le32_to_cpu(id->rd_msg->desc[0].len);
rd_msgpoints into the chunk buffer that the remote peer filled via RDMA-WRITE-WITH-IMM (rtrs_srv_rdma_done()->process_io_req()->process_read()), so desc[0].len is attacker-controlled and, before this change, was only rejected when zero. The source address is the fixed chunk start (dma_addr[msg_id]) and the source lkey is the PD-widelocal_dma_lkey, which is not tied to the chunk's MR mapping, so the verbs layer does not constrain the transfer length tomax_chunk_size.msg_idand off are bounded againstqueue_depthandmax_chunk_sizeinrtrs_srv_rdma_done(), but desc[0].len is a separate field that was not checked against the chunk size.A peer that advertises desc[0].len larger than
max_chunk_sizecan make the posted RDMA write read past the chunk's mapped region. The resulting behaviour depends on the IOMMU configuration: with no IOMMU or in passthrough mode the read may extend into memory adjacent to the chunk and be returned to the peer, which can disclose host memory; with a translating IOMMU the out-of-range access is expected to fault and abort the connection. In either case the transfer exceeds what the protocol permits and is driven by a remote peer.Reject a descriptor length above
max_chunk_size, mirroring the existing off >=max_chunk_sizebound inrtrs_srv_rdma_done(). Legitimate clients do not exceed it: the client sets desc[0].len to its MR length, which is capped at the negotiatedmax_io_size(max_chunk_size-MAX_HDR_SIZE).
Quoted 8 lines
Fixes 9cb837480424 ("RDMA/rtrs: server: main functionality")Reported-by Yuhao Jiang <[email protected]>Signed-off-by Zhenhao Wan <[email protected]>Reviewed-by Md Haris Iqbal <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Jason