Skip to content

Commit

Permalink
smb: client: remove extra @chan_count check in __cifs_put_smb_ses()
Browse files Browse the repository at this point in the history
[ Upstream commit c37ed2d ]

If @ses->chan_count <= 1, then for-loop body will not be executed so
no need to check it twice.

Reviewed-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Stable-dep-of: 24a9799 ("smb: client: fix UAF in smb2_reconnect_server()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
pcacjr authored and gregkh committed Apr 27, 2024
1 parent ba15141 commit fe1bad7
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions fs/smb/client/connect.c
Expand Up @@ -2015,9 +2015,10 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)

void __cifs_put_smb_ses(struct cifs_ses *ses)
{
unsigned int rc, xid;
unsigned int chan_count;
struct TCP_Server_Info *server = ses->server;
unsigned int xid;
size_t i;
int rc;

spin_lock(&ses->ses_lock);
if (ses->ses_status == SES_EXITING) {
Expand Down Expand Up @@ -2063,20 +2064,14 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
list_del_init(&ses->smb_ses_list);
spin_unlock(&cifs_tcp_ses_lock);

chan_count = ses->chan_count;

/* close any extra channels */
if (chan_count > 1) {
int i;

for (i = 1; i < chan_count; i++) {
if (ses->chans[i].iface) {
kref_put(&ses->chans[i].iface->refcount, release_iface);
ses->chans[i].iface = NULL;
}
cifs_put_tcp_session(ses->chans[i].server, 0);
ses->chans[i].server = NULL;
for (i = 1; i < ses->chan_count; i++) {
if (ses->chans[i].iface) {
kref_put(&ses->chans[i].iface->refcount, release_iface);
ses->chans[i].iface = NULL;
}
cifs_put_tcp_session(ses->chans[i].server, 0);
ses->chans[i].server = NULL;
}

/* we now account for primary channel in iface->refcount */
Expand Down

0 comments on commit fe1bad7

Please sign in to comment.