cifs: protect srv_count with cifs_tcp_ses_lock
authorSteve French <stfrench@microsoft.com>
Tue, 16 Nov 2021 00:02:27 +0000 (18:02 -0600)
committerSteve French <stfrench@microsoft.com>
Tue, 16 Nov 2021 16:46:22 +0000 (10:46 -0600)
Updates to the srv_count field are protected elsewhere
with the cifs_tcp_ses_lock spinlock.  Add one missing place
(cifs_get_tcp_sesion).

CC: Shyam Prasad N <sprasad@microsoft.com>
Addresses-Coverity: 1494149 ("Data Race Condition")
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/connect.c

index 82577a7a5bb147101d248c334de5d93220ce4ad3..b98711b62897708127ae14489c1cf070be010606 100644 (file)
@@ -1452,8 +1452,10 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
        tcp_ses->max_in_flight = 0;
        tcp_ses->credits = 1;
        if (primary_server) {
+               spin_lock(&cifs_tcp_ses_lock);
                ++primary_server->srv_count;
                tcp_ses->primary_server = primary_server;
+               spin_unlock(&cifs_tcp_ses_lock);
        }
        init_waitqueue_head(&tcp_ses->response_q);
        init_waitqueue_head(&tcp_ses->request_q);