Skip to content

Commit 01cf308

Browse files
committed
cifs: make locking consistent around the server session status
There were three places where we were not taking the spinlock around updates to server->tcpStatus when it was being modified. To be consistent (also removes Coverity warning) and to remove possibility of race best to lock all places where it is updated. Two of the three were in initialization of the field and can't race - but added lock around the other. Addresses-Coverity: 1399512 ("Data race condition") Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent bbd9162 commit 01cf308

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

fs/cifs/cifsglob.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ struct TCP_Server_Info {
577577
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
578578
struct smb_version_operations *ops;
579579
struct smb_version_values *vals;
580+
/* updates to tcpStatus protected by GlobalMid_Lock */
580581
enum statusEnum tcpStatus; /* what we think the status is */
581582
char *hostname; /* hostname portion of UNC string */
582583
struct socket *ssocket;
@@ -1785,7 +1786,7 @@ require use of the stronger protocol */
17851786
* list operations on pending_mid_q and oplockQ
17861787
* updates to XID counters, multiplex id and SMB sequence numbers
17871788
* list operations on global DnotifyReqList
1788-
* updates to ses->status
1789+
* updates to ses->status and TCP_Server_Info->tcpStatus
17891790
* updates to server->CurrentMid
17901791
* tcp_ses_lock protects:
17911792
* list operations on tcp and SMB session lists

fs/cifs/connect.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,11 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx)
14031403
goto out_err_crypto_release;
14041404
}
14051405
tcp_ses->min_offload = ctx->min_offload;
1406+
/*
1407+
* at this point we are the only ones with the pointer
1408+
* to the struct since the kernel thread not created yet
1409+
* no need to spinlock this update of tcpStatus
1410+
*/
14061411
tcp_ses->tcpStatus = CifsNeedNegotiate;
14071412

14081413
if ((ctx->max_credits < 20) || (ctx->max_credits > 60000))

fs/cifs/transport.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
431431
* be taken as the remainder of this one. We need to kill the
432432
* socket so the server throws away the partial SMB
433433
*/
434+
spin_lock(&GlobalMid_Lock);
434435
server->tcpStatus = CifsNeedReconnect;
436+
spin_unlock(&GlobalMid_Lock);
435437
trace_smb3_partial_send_reconnect(server->CurrentMid,
436438
server->conn_id, server->hostname);
437439
}

0 commit comments

Comments
 (0)