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@xxxxxxxx> --- 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