Skip to contentSkip to conversation

smb: client: unlock reconnect_mutex before putting session on terminate

PATCH New Elkin Cruz 1 participant 1 message Nov 25

Subsystems (3)
lore
Share & tools
lore

Elkin Cruz

author
#0 lore raw

PATCH 1/1 smb: client: unlock reconnect_mutex before putting session on terminate

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")

---

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(-)
fs/smb/client/smb2pdu.c +1 -1
index 7b7d25364e20..2fc212593fa9 100644
@@ -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;
 	}
 
Signature · 1 line
2.56.1.839.g22a8290db9-goog