Skip to content

Commit 50bd7d5

Browse files
sprasad-microsoftsmfrench
authored andcommitted
cifs: fix race condition with delayed threads
On failure to create a new channel, first cancel the delayed threads, which could try to search for this channel, and not find it. The other option was to put the tcp session for the channel first, before decrementing chan_count. But that would leave a reference to the tcp session, when it has been freed already. So going with the former option and cancelling the delayed works first, before rolling back the channel. Fixes: aa45dad ("cifs: change iface_list from array to sorted linked list") Signed-off-by: Shyam Prasad N <sprasad@microsoft.com> Acked-by: Enzo Matsumiya <ematsumiya@suse.de> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 3234649 commit 50bd7d5

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

fs/cifs/sess.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
474474

475475
out:
476476
if (rc && chan->server) {
477+
/*
478+
* we should avoid race with these delayed works before we
479+
* remove this channel
480+
*/
481+
cancel_delayed_work_sync(&chan->server->echo);
482+
cancel_delayed_work_sync(&chan->server->resolve);
483+
cancel_delayed_work_sync(&chan->server->reconnect);
484+
477485
spin_lock(&ses->chan_lock);
478486
/* we rely on all bits beyond chan_count to be clear */
479487
cifs_chan_clear_need_reconnect(ses, chan->server);
@@ -484,10 +492,9 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
484492
*/
485493
WARN_ON(ses->chan_count < 1);
486494
spin_unlock(&ses->chan_lock);
487-
}
488495

489-
if (rc && chan->server)
490496
cifs_put_tcp_session(chan->server, 0);
497+
}
491498

492499
return rc;
493500
}

0 commit comments

Comments
 (0)