Skip to content

Commit c6b363f

Browse files
hac-vSasha Levin
authored andcommitted
smb: client: Fix match_session bug preventing session reuse
commit 605b249 upstream. 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 631fe4c commit c6b363f

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

fs/cifs/connect.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,9 +1582,8 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx)
15821582

15831583
static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
15841584
{
1585-
if (ctx->sectype != Unspecified &&
1586-
ctx->sectype != ses->sectype)
1587-
return 0;
1585+
struct TCP_Server_Info *server = ses->server;
1586+
enum securityEnum ctx_sec, ses_sec;
15881587

15891588
/*
15901589
* If an existing session is limited to less channels than
@@ -1597,11 +1596,19 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
15971596
}
15981597
spin_unlock(&ses->chan_lock);
15991598

1600-
switch (ses->sectype) {
1599+
ctx_sec = server->ops->select_sectype(server, ctx->sectype);
1600+
ses_sec = server->ops->select_sectype(server, ses->sectype);
1601+
1602+
if (ctx_sec != ses_sec)
1603+
return 0;
1604+
1605+
switch (ctx_sec) {
16011606
case Kerberos:
16021607
if (!uid_eq(ctx->cred_uid, ses->cred_uid))
16031608
return 0;
16041609
break;
1610+
case NTLMv2:
1611+
case RawNTLMSSP:
16051612
default:
16061613
/* NULL username means anonymous session */
16071614
if (ses->user_name == NULL) {

0 commit comments

Comments
 (0)