Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] smb: client: Fix match_session bug causing duplicate session creation
@ 2025-03-11  1:32 Henrique Carvalho
  2025-03-11  2:53 ` Steve French
  2025-03-11 13:39 ` Enzo Matsumiya
  0 siblings, 2 replies; 4+ messages in thread
From: Henrique Carvalho @ 2025-03-11  1:32 UTC (permalink / raw)
  To: ematsumiya, sfrench, pc, ronniesahlberg, sprasad, tom, bharathsm
  Cc: linux-cifs, Henrique Carvalho

Fix a bug in match_session() that can result in duplicate sessions being
created even when the session data is identical.

match_session() compares ctx->sectype against ses->sectype only. This is
flawed because ses->sectype could be Unspecified while ctx->sectype
could be the same selected security type for the compared session. This
causes the function to mismatch the potential same session, resulting in
two of the same sessions.

Reproduction steps:

mount.cifs //server/share /mnt/a -o credentials=creds
mount.cifs //server/share /mnt/b -o credentials=creds,sec=ntlmssp
cat /proc/fs/cifs/DebugData | grep SessionId | wc -l  # output is 1

mount.cifs //server/share /mnt/b -o credentials=creds,sec=ntlmssp
mount.cifs //server/share /mnt/a -o credentials=creds
cat /proc/fs/cifs/DebugData | grep SessionId | wc -l  # output is 2

Fixes: 3f618223dc0bd ("move sectype to the cifs_ses instead of
TCP_Server_Info")
Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
---
 fs/smb/client/connect.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index f917de020dd5..0c8c523d52be 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -1825,8 +1825,11 @@ static int match_session(struct cifs_ses *ses,
 			 struct smb3_fs_context *ctx,
 			 bool match_super)
 {
+	struct TCP_Server_Info *server = ses->server;
+	enum securityEnum selected_sectype = server->ops->select_sectype(ses->server, ctx->sectype);
+
 	if (ctx->sectype != Unspecified &&
-	    ctx->sectype != ses->sectype)
+	    ctx->sectype != selected_sectype)
 		return 0;
 
 	if (!match_super && ctx->dfs_root_ses != ses->dfs_root_ses)
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-11 18:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-11  1:32 [PATCH] smb: client: Fix match_session bug causing duplicate session creation Henrique Carvalho
2025-03-11  2:53 ` Steve French
2025-03-11 13:39 ` Enzo Matsumiya
2025-03-11 18:27   ` Henrique Carvalho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox