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=1796383185; b=fJPgb+vFBRk/uQreKpZAkzLf9P2bYMCedK1fcGncYtlB8kLJL5BCgeu0+H9xaG//tweC OYyo5VNDFiAlOMWVAv1WFPDT9DB1zMp2ydEfkB0zTDqk2b+xZd0j32Avii9C0kVEfqzJX BtEakWSADoIfFDtskWmnW34TLJjPn0Yn9MxS4ZEwIlnJSwalQHGbllSSDaebjXxkVnovV j2c9y0W9o7tbZ13yf4+bD48LE02oJdsUK7xPv/EOD3xTj4HYmulcgD5CjnSUiSx5um6c3 usd4D9bu8on13hvUn/iN4FUkei3Nd2IXYYQmNvzkELpHZ00Gsj6sUDd3psEUqdCA3Iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383185; 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=n03yox4tPLFXSQ7mRmgLGgXTH+Br+60jErRalK5tLPc=; b=rKZ8tYg9OCbEd4MErn0UnV1LxWht7ZDBj8j8r+pRlxXLSAz1MexCVG7qw6zdIw2gpSwu xA/BkPC0RrWhJDkR/pLcBTSw1LctXk5502soCugc+t8nRXh9bZTt+yebUilcH9Zvpx9lE oI2XL1Pi6Ji9V/8K3h+owlOyKm1FhYHUlGI+3C3kQ9WVgtAE6kZsqlx7Q+88c3uzxY7v0 mWBgTL8sMAOnlcfHDPXyVJTmYN2ddHy1Zfpt0ZTi0Q48TDPnqMMo3u3bPqxytHmu7wWLX tXYae6Z+pP2vgZUDDpd/XM7Iyk8DygEH96m6ZAyv42cLZBbFj5kUZeP43dq3fekGV8g== 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=IPtqjag+; 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 BE833606A32D; Fri, 4 Dec 2026 11:19:45 +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=IPtqjag+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 357D21F00934; Fri, 4 Dec 2026 11:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383185; bh=n03yox4tPLFXSQ7mRmgLGgXTH+Br+60jErRalK5tLPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IPtqjag+0Cza5cXp0DIGD0QqPJTgOhToL2GbveghdK+fQN+jXx6LKdsguYINrJ3mh BJTQmIPIWRAOfWqmLc73I2aEO6O6SHww9E32qva9SIKbmiaKZI3WvTFS169dqHoavY +w+XdByxFD4RzbcFkySjoMDG4jGsuo3+4iBh2xtE= 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.12 117/555] smb: client: hold server ref while queueing reconnect work Date: Fri, 4 Dec 2026 19:02:40 +0900 Message-ID: <20261204100612.368071435@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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: Replaced the upstream smb3_update_ses_channels() and cifs_queue_server_reconn() calls with this tree's cifs_chan_skip_or_disable() and mod_delayed_work(), and left the local declaration context unchanged. ] 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 8bbeaa106287c..19d3de220e394 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -217,6 +217,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; @@ -455,6 +456,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; @@ -481,6 +496,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