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=1796386075; b=eaOO3BmdC7wSEGOfzPpXpOOgdQARJ9sBwBkxwQw9CszlieC+wKVzxhMJcDuKM0V/5T/E ne2sY/HafDViBU/7ctuKxaNLy9mL5GKGt+gfvyU2C5cwd/+TlkOZof/1Ds7hni1LV3ryX Z6QzxZ1ow0zMhzq3YSGgVR/MWla0vgr8PHbjmLbXncsL+LUt7lFbrSBt0dJC9ilQjefl1 Q2kFQxR/LwmYlrjAVhW3kuaul+s5GCJaje8DKO4fiSHkptUXvvDLZ7Rr7iJ+zs8In2FKC JzIxc8L8TfmG3IKeFjwBbwE3hDNYw9Tmfld8gfeoKoNCDJMkgy2hxEsZhu57MPcRaNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386075; 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=AMCBWiM2pMvNM/7ePOekNL3gK4zWQU+3BFgxN2EfnVk=; b=Ze8JaWQ5JBwC3Cl1EqnJ4nstNRb+bMQBkOIw9W6wDYTj5qb7wBwSm9ePDbulr4i5kTxd xGaRNboGFjshQxb8IXBMQorwsJSTU6Zo/ba18EIeaf+OgV2nzIvyinLcyhbItjYYZ7KFr 2WBE5XwSc5+KnXOvSEyWW7011oWfJXdivSroE1E3AlCQmGbLdOngnlj+kja5NbXNT8FhN PP1WaGu96kG1e4CWM80jX9gkHyf8OwbXq7zw8NRgPRLjHkDii4sVD8RGRZm3JS6Zf8c+T lDNYzKSH83Sgxn6wD6Ky0QlVOg7/9RzY/a8jUr4pSBPK/YWMyguAc0m0ag4Mj4GkiDA== 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=iSE3Qut3; 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 2D9FA606A32F; Fri, 4 Dec 2026 12:07:55 +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=iSE3Qut3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96F261F000C2; Fri, 4 Dec 2026 12:07:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386075; bh=AMCBWiM2pMvNM/7ePOekNL3gK4zWQU+3BFgxN2EfnVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iSE3Qut3BG4o4/E1dzlq4h5WZk0zatRggYzQuv+Z7+o0s5TUH6LF75jqRHZHRWNJq IMPx5VrY0TFUpVUQ1vdsGSAYg9+jGhJsUusASj27LTvd/tLyeAuIci6t26rLQnulHU hvUhpRCYIiZN30K5uGeNUIlXHk1iHMsARuRunnZs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joseph Qi , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.6 0817/1167] smb: client: hold server ref while queueing reconnect work Date: Fri, 4 Dec 2026 19:04:04 +0900 Message-ID: <20261204100723.405511562@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joseph Qi [ Upstream commit f02d249e9756b78990aaaa1635e47e06deb2cb51 ] When query_server_interfaces() returns -EOPNOTSUPP on a secondary channel, smb2_reconnect() calls smb3_update_ses_channels() which for a channel runs cifs_chan_skip_or_disable(). That clears the channel's slot in the session and calls cifs_put_tcp_session(), which can drop the last reference of the channel and tear it down. smb2_reconnect() then falls through to skip_add_channels and queues reconnect work on that server, using a server that may already be freed. The send path obtained the channel from cifs_pick_channel(), which does not take a reference, so the session's channel reference is the only one. Take our own reference on the channel before calling smb3_update_ses_channels() and drop it after the reconnect work has been queued, so the channel cannot be freed while it is still used. Fixes: f591062bdbf4 ("cifs: handle servers that still advertise multichannel after disabling") Cc: stable@vger.kernel.org Signed-off-by: Joseph Qi Signed-off-by: Paulo Alcantara [ sashal: adapted to older code: open-coded the reconnect work queueing and channel disable calls (mod_delayed_work, cifs_chan_skip_or_disable) and adjusted variable declaration context. ] Signed-off-by: Sasha Levin --- fs/smb/client/smb2pdu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index c24f912581f48..413b9f6fa609e 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -214,6 +214,7 @@ static int smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, struct TCP_Server_Info *server, bool from_reconnect) { + bool hold_server_ref = false; int rc = 0; struct nls_table *nls_codepage = NULL; struct cifs_ses *ses; @@ -452,6 +453,20 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, * treat this as server not supporting multichannel */ + /* + * If server is a secondary channel, + * cifs_chan_skip_or_disable() called below may + * drop its last reference, so hold our own + * reference until the reconnect work below has + * been queued. + */ + spin_lock(&cifs_tcp_ses_lock); + if (server->srv_count) { + server->srv_count++; + hold_server_ref = true; + } + spin_unlock(&cifs_tcp_ses_lock); + rc = cifs_chan_skip_or_disable(ses, server, from_reconnect); goto skip_add_channels; @@ -478,6 +493,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, if (smb2_command != SMB2_INTERNAL_CMD) mod_delayed_work(cifsiod_wq, &server->reconnect, 0); + if (hold_server_ref) + cifs_put_tcp_session(server, from_reconnect); atomic_inc(&tconInfoReconnectCount); out: -- 2.53.0