Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Elkin Cruz <elkin@google.com>
To: Paulo Alcantara <pc@manguebit.org>, Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	 Tom Talpey <tom@talpey.com>,
	Bharath SM <bharathsm@microsoft.com>,
	linux-cifs@vger.kernel.org,  samba-technical@lists.samba.org,
	linux-kernel@vger.kernel.org,  llvm@lists.linux.dev,
	irogers@google.com, Elkin Cruz <elkin@google.com>,
	 stable@vger.kernel.org
Subject: [PATCH] smb: client: unlock reconnect_mutex before putting session on terminate
Date: Wed, 25 Nov 2026 21:00:25 +0000	[thread overview]
Message-ID: <20261125210025.1277771-1-elkin@google.com> (raw)

In smb2_reconnect_server(), when server->terminate is set, the early
exit path calls cifs_put_tcp_session(server, true) while still holding
pserver->reconnect_mutex and unlocks pserver->reconnect_mutex
afterwards. Dropping the last session reference can free server (which
equals pserver for primary channels), causing mutex_unlock() to touch
freed memory; the normal done: label at the end of the same function
explicitly unlocks reconnect_mutex before calling cifs_put_tcp_session().

Unlock pserver->reconnect_mutex before calling cifs_put_tcp_session() in
the server->terminate branch as well.

Fixes: ee1d21794e55 ("cifs: handle when server stops supporting multichannel")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---

I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).

Thanks,
Elkin

 fs/smb/client/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 7b7d25364e20..2fc212593fa9 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -4390,8 +4390,8 @@ void smb2_reconnect_server(struct work_struct *work)
 
 	/* if the server is marked for termination, drop the ref count here */
 	if (server->terminate) {
-		cifs_put_tcp_session(server, true);
 		mutex_unlock(&pserver->reconnect_mutex);
+		cifs_put_tcp_session(server, true);
 		return;
 	}
 
-- 
2.56.1.839.g22a8290db9-goog


             reply	other threads:[~2026-11-25 21:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 21:00 Elkin Cruz [this message]
2026-11-26 12:16 ` [PATCH] smb: client: unlock reconnect_mutex before putting session on terminate Paulo Alcantara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125210025.1277771-1-elkin@google.com \
    --to=elkin@google.com \
    --cc=bharathsm@microsoft.com \
    --cc=irogers@google.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sprasad@microsoft.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox