]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smb: client: Fix match_session bug preventing session reuse
authorHenrique Carvalho <henrique.carvalho@suse.com>
Tue, 11 Mar 2025 18:23:59 +0000 (15:23 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 Mar 2025 19:54:28 +0000 (12:54 -0700)
[ Upstream commit 605b249ea96770ac4fac4b8510a99e0f8442be5e ]

Fix a bug in match_session() that can causes the session to not be
reused in some cases.

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

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

Cc: stable@vger.kernel.org
Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/client/connect.c

index fb51cdf552061797e6046270482898c62647d66c..d327f31b317db9768f9715f9f9f860c59417a296 100644 (file)
@@ -1873,9 +1873,8 @@ static int match_session(struct cifs_ses *ses,
                         struct smb3_fs_context *ctx,
                         bool match_super)
 {
-       if (ctx->sectype != Unspecified &&
-           ctx->sectype != ses->sectype)
-               return 0;
+       struct TCP_Server_Info *server = ses->server;
+       enum securityEnum ctx_sec, ses_sec;
 
        if (!match_super && ctx->dfs_root_ses != ses->dfs_root_ses)
                return 0;
@@ -1887,11 +1886,20 @@ static int match_session(struct cifs_ses *ses,
        if (ses->chan_max < ctx->max_channels)
                return 0;
 
-       switch (ses->sectype) {
+       ctx_sec = server->ops->select_sectype(server, ctx->sectype);
+       ses_sec = server->ops->select_sectype(server, ses->sectype);
+
+       if (ctx_sec != ses_sec)
+               return 0;
+
+       switch (ctx_sec) {
+       case IAKerb:
        case Kerberos:
                if (!uid_eq(ctx->cred_uid, ses->cred_uid))
                        return 0;
                break;
+       case NTLMv2:
+       case RawNTLMSSP:
        default:
                /* NULL username means anonymous session */
                if (ses->user_name == NULL) {