From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796384786; b=E7pFnnlAilCrwaeKNLsbaYLjcdWML9e6r5TihW4bup0ZfNOsEXsBRX9oEFRY597QK1MH gH5t/Bp4stkNCe/u4Sra6vdDWNx8xW7eJlouLSLIMohQFM0NvM22lK9HdGoYynjYmZOAZ J5tS3iuE5dDKQjVm36BzA+V2lrMabB2wP4wiMZoHGT+BVPouv3FtpZ5bKDXTt4lO0ujIc 66gGfpzsSvJ5BjreT9ZACF8ydoPM2J6+ejWT9pahSL4kSLRbCvTzCuvitw8V/MoeRmhof 5S3z6M6I3+h/UgMQJ0Omt1dnbbtLYRTvSae7CT5EV3ZZlUUjpI/RR1ksRVFevAfdOhQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384786; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=JYN3KX26svVQJxFha8DS11BGpY+eYUJmSPBHBsWacgc=; b=cZ9WeD3EzhnrFy3IsA3VHQQt0UDXFUdRlf8Fk6vDYzxJffhzkGwvC73BXd1wtAresPOn 83DmJOrh6tFskRl4UYpTu4L7tSvCNy1XZgTJnp72w3Ux8W9nGKA5lVFeCodX/oEhylhy+ QNBEVFrjsR6UMSPG/Us3gLTiX78N6+C7cH09qbM2gMd9O91CkqgPhzd9MXFNmEUbZ2HSv rUiXJE9CpTC1t1Y/uOXdHe1DBr413AgX22zTQyNL5Ev+cOEZlEZmVNqtaKg1t53eMIk2n FSed8Uai77xleFuoDAYsWs4eYT2sq+7BOyH5AbqZk8rN6kTIDZpba2YUEuiDThu6UAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SeDaB7Tf; 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 8DC54606A322 for ; Fri, 4 Dec 2026 11:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SeDaB7Tf Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2A8B1F000C2; Fri, 4 Dec 2026 11:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796384786; bh=JYN3KX26svVQJxFha8DS11BGpY+eYUJmSPBHBsWacgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SeDaB7TfJt0eNdWs4axVyAdTdXSHWZAUHW1PN5caR+j5mTDz9mUPu3FG1lKFbefYR gP7Te23HHimfInmbGF3P3PzXCAed7i028Oa01H4oNlj3yo7EckHwz1SUIi0ylJ1FiQ cr6oPHx1qMerLcusogzp46OBy1PSSB8qFPYr14//FzqazyC/I8xU4SAel1pdPtgWVF VSoUxYHGOzg8eknKXoGEXN9Hhwg9fz8vfmRpEcc5icURfa+921ioMnpXVFcV7VHn/i rhcj+0IhvU21eUts2gjM5XAJLgyJab77qvAQML+z6rzVmvKdYtwLFh9xsRBHeQgrnS /oaoCHX7eqaWA== From: Sasha Levin To: stable@vger.kernel.org Cc: ozgun kultekin , Namjae Jeon , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.12.y] smb: client: do not let the server grow a write subrequest Date: Fri, 4 Dec 2026 06:46:24 -0500 Message-ID: <20261204114556.2780756-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120212-silk-envoy-584c@gregkh> References: <2026120212-silk-envoy-584c@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: ozgun kultekin [ Upstream commit f834c81f108f8bdb0e3aa8375a536fb6dda56c70 ] smb2_writev_callback() takes the byte count from the SMB2 WRITE response, masks it with 0xFFFF if it is larger than the request (for old OS/2 servers), and then copies it into wdata->subreq.len. A server can return a count that is still larger than the request after the mask, for example 0x8002 for a 5-byte write or 0xFFFF for a 4 KiB write, and the subrequest then covers data that was never sent. netfs uses the subrequest length to decide how far the write collector may advance. With a grown subrequest the collector moves collected_to past the data that was issued: netfs_writeback_unlock_folios() walks folio_queue slots that were never filled, and rolling_buffer_delete_spent() frees folio_queue segments that later in-flight subrequests still use. This is a use-after-free that a malicious or broken server triggers from an ordinary write: BUG: KASAN: slab-use-after-free in netfs_limit_iter+0xed4/0x1040 Read of size 1 at addr ff11000010561511 by task kworker/u8:4/63 Workqueue: events_unbound netfs_write_collection_worker netfs_limit_iter+0xed4/0x1040 netfs_retry_writes+0x1410/0x1e90 netfs_write_collection+0x2647/0x3880 netfs_write_collection_worker+0x1cd/0x3e0 Allocated by task 141: netfs_folioq_alloc+0x39a/0x470 rolling_buffer_init+0x29/0xc0 netfs_create_write_req+0x12f/0x840 Freed by task 42: rolling_buffer_delete_spent+0xb1/0x220 netfs_write_collection+0x1f62/0x3880 Never change the subrequest length from the response. If the count is still larger than the request after the mask, fail the write with -EIO and record it with a new write_overlarge trace point, like the read path does with read_overlarge. A short count still returns -ENOSPC as before. The folio_queue form of the use-after-free exists since commit cd0277ed0c18 ("netfs: Use new folio_queue data type and iterator instead of xarray iter"). Fixes: 3ee1a1fc3981 ("cifs: Cut over to using netfslib") Cc: stable@vger.kernel.org Signed-off-by: ozgun kultekin Reviewed-by: Namjae Jeon Signed-off-by: Paulo Alcantara [ sashal: Replaced smb_EIO2() trace call with plain -EIO, dropped the trace.h hunk, and kept the older write-completion tail (wdata->result = -ENOSPC) instead of the newer restructured form. ] Signed-off-by: Sasha Levin --- fs/smb/client/smb2pdu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 19d3de220e394..c8d273cb3fb1d 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4964,12 +4964,20 @@ smb2_writev_callback(struct mid_q_entry *mid) if (written > wdata->subreq.len) written &= 0xFFFF; + /* + * The server must not report more bytes than were sent. netfs + * uses the subrequest length to work out which folios this + * write has finished with, so it must not be changed here. + */ + if (written > wdata->subreq.len) { + result = -EIO; + break; + } + cifs_stats_bytes_written(tcon, written); if (written < wdata->subreq.len) wdata->result = -ENOSPC; - else - wdata->subreq.len = written; break; case MID_REQUEST_SUBMITTED: case MID_RETRY_NEEDED: -- 2.53.0