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=1796221541; b=4c9RcnZXgcotm1zkCWQZ1P/K5KNLdcHIk5GaYOY3MoPeFa079fcEdRvM4vwiY/9eDaNO UCfpR5rZS8RV18AJ8PCTgPjTOE+atdLzsRgXMCvQ5QSGQNfNVqqyHYx9DGQbVGKVJxu0w AcGrzP4wh1oQE1CMitxmRKbiX5ygZOih94uzvJpgs++8x4GTwnIGMmoMvGYxril1z7qv+ Soe8k66qiCHPCTZw/tL/ie6OvjF/qQPCffwDlPq+nDVMTApEYoN6Bia2l51GSDjeecgfq 3bt4i3t1tl0Cz3MKJVMF5HLtgaJCqvzc5dJ8HTSjAGwP1G2yR2HideLYJeJ0uIKjmgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221541; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=cno+XWerBQpySLn55r0mM30lA/ravv4YE5FcrATVhZU=; b=NyJ9yXv6NW56OYWT1wwnKi3LYeA6yErkXgSmkJP913sQst27XOcjS6G9gNmoKkQ1CERS QaViMempE6WKwClztfS3VRa4nwjJAi35SAxtMfwrzwOeUiDAp8JEprIvbC+is82ZHoLO8 HqP5P6mqiSOjF48NeWN54541m+6VlDYx2jvToupKv6a3birOZr8z3IjSgo0hlsexGRoNU lMH3U+NbbA8tSY+myX61jewSuwnlH59JyJpCXk5lO1wVrWkZUCrM4/MA8FR5D26iZ9uyf ed5rhS00TrzGwvmVc9EIScFM9ongi4thULPTJI5sYZbdJfFBNzEFCUbhCOR0FvLjM0Q== 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=vj3SpwPu; 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 C7102606A31A for ; Wed, 2 Dec 2026 14:25:41 +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=vj3SpwPu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DE7A1F00923; Wed, 2 Dec 2026 14:25:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221541; bh=cno+XWerBQpySLn55r0mM30lA/ravv4YE5FcrATVhZU=; h=Subject:To:Cc:From:Date; b=vj3SpwPu1zhAoUACO2c9JSKqzFnQlfBT+nrJeELqaYzz5kX++LZB5ObOCJoypc5OW CkbuzcP7en5gXwpjUXOFkXX9+3V/byCX4G986Utu0eI10jT87nYWseXrN2ssvxQiL+ 4EH1XQbq8FTrIC0kR4j2duEEcAXO9alxTDdgFMQ0= Subject: FAILED: patch "[PATCH] smb: client: do not let the server grow a write subrequest" failed to apply to 6.12-stable tree To: ozgunkultekin@gmail.com,linkinjeon@kernel.org,pc@manguebit.org Cc: From: Date: Wed, 02 Dec 2026 14:55:12 +0100 Message-ID: <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-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.12-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y git checkout FETCH_HEAD git cherry-pick -x f834c81f108f8bdb0e3aa8375a536fb6dda56c70 # git commit -s git send-email --to '' --in-reply-to '2026120212-silk-envoy-584c@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From f834c81f108f8bdb0e3aa8375a536fb6dda56c70 Mon Sep 17 00:00:00 2001 From: ozgun kultekin Date: Tue, 17 Nov 2026 16:21:59 -0800 Subject: [PATCH] smb: client: do not let the server grow a write subrequest 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 diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index b26bfb4bd91a..2f05ba613f34 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5181,14 +5181,23 @@ smb2_writev_callback(struct TCP_Server_Info *server, 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 = 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); diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h index 5331ce6dc8b3..18760a81949c 100644 --- 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")