Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795045948; b=4FgqKQmpdPDlt5+I1VriTltaIm4iFPK+VCDhouGKaeZkuofMGt7H8iL1Ab3dWbE4ZEjw jYGGPH4ay/ItMbMbRfZsjsfAO7lo5/CWXsm4mocDBLwCWqdNOEckfRkARxs5d7RYqZlt7 CITC9Of2qfzEm9QTw9WytpvtTLs7f5/E90wzM7h1kb+1NB26nBaKxZnL7UjhylM/8n+TO az9xiC9gxFsHhBlEODnapjYfCmibqs5w2ryXcFQ3jcTOB1THBuAMgg0xABR9aaQ5GYJPH YLmJP0rnDS94+IGs1B0j56ajyC4P7xk2mfIiPsmuG5Ntkge6IznyPB7mkDq/bMRLoyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795045948; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=wSB0dXRaJr6mDmEgZly8oNwlSzJwbCuzWF4aI9PaNB0=; b=WYhaZRWsOwh2W4YoxT1LDJf1gzNWtJ+j/TYIRwlXjfdQ9xcV/jj6J4nBjNUfh1tdVUHn 7qBSj8KuzjMq3bPOhQY785MuqRix78Puw1lHg44KYgIC37fuiZ0DYHcpdi/NFi71m7Fm6 pkGPnPZ94IZ2HvLhKnqb1MGYqVRY4ZLEF7kl6Ndkr/XAznNNrEX79BFR9UIrb/8dYwRfr IS+oD6o73Ds+0jseccDg18J9c9nPlH3SxGBylCkyfgkezDMGoDpO85uY6sXUvJOlAfP3X JgSsoKwI+xmtHWnMgprczCmze6NaDd1Gxorqa0Ehmi4ys7J9XdqKOhX5Kd5olFHtHlA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=aCUFo0VC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E214606A32C; Wed, 18 Nov 2026 23:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=aCUFo0VC Received: by smtp.kernel.org (Postfix) with ESMTPSA id C46FE1F000C4; Wed, 18 Nov 2026 23:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795045948; bh=wSB0dXRaJr6mDmEgZly8oNwlSzJwbCuzWF4aI9PaNB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aCUFo0VCRM+DT889k2WnRfQYXMr1BdsgMdWCRw6friJAqG0Wym1UDYFxX2gMyHP6p eJ4QrYYSbcdQm7dWByCeMlU6PaySuLljxelClslQ+DDwWOLZdXjXP1RFc+hsHN15yG 0JZzqEHNVRmblyO3iB6J15JscObC7fmGI9Ln+HMg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Abdifatah Suruur , Namjae Jeon , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.1 1105/2857] smb: client: validate the data area in SMB2_read() Date: Wed, 18 Nov 2026 15:35:39 +0100 Message-ID: <20261118150241.421778636@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Abdifatah Suruur [ Upstream commit 2ec9cdf469dd32bcf33073aeb30c08e9356e0ca1 ] SMB2_read() copies le32_to_cpu(rsp->DataLength) bytes from (char *)rsp + rsp->DataOffset without checking that the range lies within the response actually received. A READ response with DataOffset == 0 makes smb2_get_data_area_len() zero the data length, so smb2_check_message() accepts a frame as short as the fixed response, while SMB2_read() still uses the server-supplied DataLength, capped only by CIFS_MAX_MSGSIZE and the caller's length. A malicious server can answer the synchronous read used by the mfsymlinks (or SFU) symlink parser with an 81-byte READ response carrying DataOffset 0 and DataLength 1067, making the client copy 1067 bytes from a 448-byte receive object (KASAN slab-out-of-bounds; up to 16 KiB in the general case). Clamp a zero (or header-overlapping) DataOffset to read_rsp_size, as handle_read_data() does for the asynchronous path, and reject the response unless DataOffset + DataLength fits within rsp_iov.iov_len. The SMB1 helper was fixed the same way in 5be5bdda5863. Fixes: d8e050398d23 ("CIFS: Add readpage support for SMB2") Cc: stable@vger.kernel.org Signed-off-by: Abdifatah Suruur Reviewed-by: Namjae Jeon Signed-off-by: Paulo Alcantara [ sashal: Replaced the unavailable smb_EIO2() helper call with a direct rc = -EIO assignment. ] Signed-off-by: Sasha Levin --- fs/smb/client/smb2pdu.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 716662453e19d..75942195b619c 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4559,6 +4559,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, struct kvec iov[1]; struct kvec rsp_iov; unsigned int total_len; + u16 data_offset; int flags = CIFS_LOG_ERROR; struct cifs_ses *ses = io_parms->tcon->ses; @@ -4616,8 +4617,28 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, *nbytes = 0; } + data_offset = rsp->DataOffset; + if (data_offset < io_parms->server->vals->read_rsp_size) { + /* + * win2k8 sometimes sends an offset of 0 when the read is beyond + * the EOF. Treat it as if the data starts just after the header, + * as handle_read_data() does. + */ + cifs_dbg(FYI, "data offset %u inside read response header\n", + data_offset); + data_offset = io_parms->server->vals->read_rsp_size; + } + + /* The data area must lie within the response actually received */ + if (*nbytes && (size_t)data_offset + *nbytes > rsp_iov.iov_len) { + cifs_dbg(FYI, "bad data offset %u length %u for response of %zu\n", + data_offset, *nbytes, rsp_iov.iov_len); + rc = -EIO; + *nbytes = 0; + } + if (*buf) { - memcpy(*buf, (char *)rsp + rsp->DataOffset, *nbytes); + memcpy(*buf, (char *)rsp + data_offset, *nbytes); free_rsp_buf(resp_buftype, rsp_iov.iov_base); } else if (resp_buftype != CIFS_NO_BUFFER) { *buf = rsp_iov.iov_base; -- 2.53.0