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=1796381425; b=aZ78PSNot+7NNJbkoakwyKKAo1+/b5I6ymsZ2U1GjjWNEIGh39i6r3sJJivAVt0B+8Zm gGyEOnEuTum9+CcXmJpXjUIeqtBjC8mbmY4mHZkIdqPiv8N4OpP2Zc/Neu39kRz3t/3+H MLYaC9twzA0F83rZLF3t50yd9SoP6Jzbu+zPqkUkms8X/0fyvT+sz/+4XV9gc4FqcAX9w SAATsVgeM73n9TKDyv2LoFjtRSVPta1V0yB8t8OR6e1TOIXehxLAUvP4ZFgvCZeDoWpjd /mUJHgIyC2FFdnvusOpbrq9/NWOcPwoI3N4m77nO8Vnxmcfo0TyuvDIDgeqLnp+CbJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381425; 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=5zBvkRHyKt2qy7lXUs3EBSRWuUF3AUOMQQFIDcCcJZE=; b=ahzKqSmQMJVn9MRGEz1WZaeA6gvH1mCBfTr0di9TV9tFzbYj3mut53Kk3Wsk/OzBnTJz DRkk75KLoY7I6mmFwIh/mMUD+cD8dvNW74iSIAeEMNWKKx5iV+7WTgPYMrRq9wQu0DE/+ 2M5ZWvXcIYYznaDlsBGLDyT5kn4wgjmvrizwotRa2cauuQQEEWVweBnrxiMgRrNIlUiSW mSrLOc7xsjgItHJwAC/23hxE8rXtu5jDWTagU/R9ecdko1Qf1y1MWmL/F+6y5bYYZoZyy kiMMt8CL7MQCQYUtALD3oPV/c3mdr75zcoC8VPxP3Z86UtG6ddaqW62kk5gyfBIcHYw== 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=u73XC4V2; 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 E7826606A32C; Fri, 4 Dec 2026 10:50:24 +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=u73XC4V2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D78A1F000C2; Fri, 4 Dec 2026 10:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381424; bh=5zBvkRHyKt2qy7lXUs3EBSRWuUF3AUOMQQFIDcCcJZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u73XC4V2nDgcl41TOlemUMyoxNXgOUs5AtrRAg8+ITj3J+Fmd0oIEmpr7tWPf63OC GeTorTL/X/kzpkXtiX/rwT9OTowXwyQldeG1wCJOQ0yfzN+CD1TJFgSKgbkT7B0OV0 qxF+c7ecBkVvUWyAlzHUWoko+1xdxRUX+Dbp2eCA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, ozgun kultekin , Namjae Jeon , Paulo Alcantara Subject: [PATCH 7.3 661/742] smb: client: do not let the server grow a write subrequest Date: Fri, 4 Dec 2026 19:08:45 +0900 Message-ID: <20261204100652.637209192@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: ozgun kultekin commit f834c81f108f8bdb0e3aa8375a536fb6dda56c70 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- fs/smb/client/smb2pdu.c | 17 +++++++++++++---- fs/smb/client/trace.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5162,14 +5162,23 @@ smb2_writev_callback(struct TCP_Server_I 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 = smb_EIO2(smb_eio_trace_write_overlarge, + written, wdata->subreq.len); + break; + } + cifs_stats_bytes_written(tcon, written); - if (written < wdata->subreq.len) { + if (written < wdata->subreq.len) result = -ENOSPC; - } else if (written > 0) { - wdata->subreq.len = written; + else if (written > 0) __set_bit(NETFS_SREQ_MADE_PROGRESS, &wdata->subreq.flags); - } break; case MID_REQUEST_SUBMITTED: trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted); --- a/fs/smb/client/trace.h +++ b/fs/smb/client/trace.h @@ -153,6 +153,7 @@ EM(smb_eio_trace_user_iter, "user_iter") \ EM(smb_eio_trace_write_bad_buf_type, "write_bad_buf_type") \ EM(smb_eio_trace_write_mid_state_unknown, "write_mid_state_unknown") \ + EM(smb_eio_trace_write_overlarge, "write_overlarge") \ EM(smb_eio_trace_write_rsp_malformed, "write_rsp_malformed") \ E_(smb_eio_trace_write_too_far, "write_too_far")