]> git.hungrycats.org Git - linux/commitdiff
smb: smbdirect: fix buffer length underflow in RDMA transfers
authorStefan Metzmacher <metze@samba.org>
Fri, 23 Oct 2026 10:26:09 +0000 (19:26 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:12 +0000 (12:06 -0500)
commit 7193241a49c958782ba4b8df06da3734d1e317d2 upstream.

When a remote buffer descriptor is larger than the remaining local
buffer, smbdirect_connection_rdma_xmit() clamps its length and sets
buf_len to zero. The common accounting code then subtracts the clamped
length from buf_len, causing it to underflow. If another descriptor
follows, the loop processes it with a wrapped remaining length and
includes memory beyond the local buffer in the RDMA transfer.

A client can trigger an out-of-bounds kernel write with an SMB WRITE
request, or an out-of-bounds kernel read with an SMB READ request, by
supplying multiple RDMA buffer descriptors with an oversized descriptor
before the last one.

Remove the premature assignment to buf_len. Subtracting the clamped length
already consumes the remaining buffer, so the next iteration stops and
only descriptors within the local buffer are used to build work requests.

Fixes: e628bf939aaf ("ksmbd: reduce descriptor size if remaining bytes is less than request size")
Cc: stable@vger.kernel.org
Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-33549
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
[ metze: in 6.18 the code is smb_direct_rdma_xmit() in
  fs/smb/server/transport_rdma.c ]
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/server/transport_rdma.c

index 3f9bcd10a0b3f3e46b16bd07d5a6a65ff89bc33f..fed0c7db224f11c9c168678635e3a8d6b4d22702 100644 (file)
@@ -1724,7 +1724,6 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
                if (desc_buf_len > buf_len) {
                        desc_buf_len = buf_len;
                        desc[i].length = cpu_to_le32(desc_buf_len);
-                       buf_len = 0;
                }
 
                credits_needed += calc_rw_credits(sc, desc_buf, desc_buf_len);