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=1796381594; b=4mdxwCJ8aJQVLB2q4WpdiOQdaCb25H9J9k7UjkQUs7a6QmfnJI226RY6WT3iMojpnAKF vnNaczQi2Bzs8EJrVSQ8ep6Ewi7m8JW9AJ6PkbqulQHh5bO4zhRVfuKFjlQHQeVGuM4SY XnoB4wrnPB6Wed9MGDoJ1tmb+MtmgfJXnHITIZebMpA8cFrvPKV4dM9Z+rhvKb5BH8gXb kix69AysWm4lMPaRBLmYjVDh0lbdBO5OUDCO+SGFTXc238gyunyq7TAHSCbVz5XUn90RJ l3rCzOv/ZbvpIPQO67G4AB2ucShP0OkcjP2B2/x9ZMXi1CJrk9j/zgyndsmZIx6ZpHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381594; 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=LY3OEDWXOz4bQ82hvFSWWw20iuv30rfben4NLPU+F5Q=; b=LEYbQ5JRDcrSZqPGQ85k1xD0csG4qcGR/bUdReMG2hZYzgmCS2B3/zrVY0Y73wpuI1xr 39KgRy9/g912TBeAVxG3IBgFwBeBGPrn44DQ9CwtvuLCfO9hiRK3NaYBl0loQFS6S6cok FvocVEnAw3XxYtAU2MrXVVe29OyOyFnjAvd7ipbz2gQazNofm5bvVu08ZrDCq3F1KXAIA bje4l7z4J2s1qQqx0g1YsWA+o5iDmHUzbcy3SfQuEmNC6tylmIqhHXs8IIAUJMlDhIbBx xsa002pLW3SBL0DAq5AVFoKJZW17TRSJUM3avbQEvCrMOB97fe0gzUskMdtQCH4/XrQ== 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=JduVGDQJ; 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 7D357606A322; Fri, 4 Dec 2026 10:53:14 +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=JduVGDQJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 981BF1F000CE; Fri, 4 Dec 2026 10:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381594; bh=LY3OEDWXOz4bQ82hvFSWWw20iuv30rfben4NLPU+F5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JduVGDQJi29oU2mvZ5CsAY6P2jTtTdiBi+lUSSR0yyEz47f8iGxyOAr7bGYf32qMJ +ufFrzFUOLFQOW8oAvRAl+PlspFe06eRjpMsEHtQRoLvZEnmh73nIfHtn/d+n+IdtN QU026T9kkKGzd6zhSV3BbrEKIpNYpPv1eTYJnX8w= 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.18 091/703] smb: client: hold server ref while queueing reconnect work Date: Fri, 4 Dec 2026 18:59:50 +0900 Message-ID: <20261204100630.162608904@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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: Used cifs_chan_skip_or_disable() in place of smb3_update_ses_channels(), which doesn't exist in this tree, while keeping the same extra-reference locking and put as upstream. ] Signed-off-by: Sasha Levin --- fs/smb/client/smb2pdu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 7b95493b94642..17230f94eea3b 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -219,9 +219,10 @@ static int smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, struct TCP_Server_Info *server, bool from_reconnect) { + bool hold_server_ref = false; struct cifs_ses *ses; - int xid; int rc = 0; + int xid; /* * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so @@ -439,6 +440,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; @@ -465,6 +480,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