Skip to content

Commit fb0800c

Browse files
hac-vgregkh
authored andcommitted
smb: client: Fix match_session bug preventing session reuse
[ Upstream commit 605b249 ] 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>
1 parent 7dc9abf commit fb0800c

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

fs/smb/client/connect.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,9 +1884,8 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
18841884
/* this function must be called with ses_lock and chan_lock held */
18851885
static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
18861886
{
1887-
if (ctx->sectype != Unspecified &&
1888-
ctx->sectype != ses->sectype)
1889-
return 0;
1887+
struct TCP_Server_Info *server = ses->server;
1888+
enum securityEnum ctx_sec, ses_sec;
18901889

18911890
if (ctx->dfs_root_ses != ses->dfs_root_ses)
18921891
return 0;
@@ -1898,11 +1897,20 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
18981897
if (ses->chan_max < ctx->max_channels)
18991898
return 0;
19001899

1901-
switch (ses->sectype) {
1900+
ctx_sec = server->ops->select_sectype(server, ctx->sectype);
1901+
ses_sec = server->ops->select_sectype(server, ses->sectype);
1902+
1903+
if (ctx_sec != ses_sec)
1904+
return 0;
1905+
1906+
switch (ctx_sec) {
1907+
case IAKerb:
19021908
case Kerberos:
19031909
if (!uid_eq(ctx->cred_uid, ses->cred_uid))
19041910
return 0;
19051911
break;
1912+
case NTLMv2:
1913+
case RawNTLMSSP:
19061914
default:
19071915
/* NULL username means anonymous session */
19081916
if (ses->user_name == NULL) {

0 commit comments

Comments
 (0)