linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [SMB3][PATCH] address minor Coverity warning
@ 2021-06-25 19:05 Steve French
  0 siblings, 0 replies; only message in thread
From: Steve French @ 2021-06-25 19:05 UTC (permalink / raw)
  To: CIFS

    There was one place where we weren't locking CurrentMid, and although
    likely to be safe since even without the lock since it is during
    negotiate protocol, it is more consistent to lock it in this last remaining
    place, and avoids confusing Coverity warning.

    Addresses-Coverity: 1486665 ("Data race condition")
    Signed-off-by: Steve French <stfrench@microsoft.com>

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index fc6b08e5ebbc..3100f8b66e60 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -621,7 +621,7 @@ struct TCP_Server_Info {
        /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
        unsigned int capabilities; /* selective disabling of caps by smb sess */
        int timeAdj;  /* Adjust for difference in server time zone in sec */
-       __u64 CurrentMid;         /* multiplex id - rotating counter */
+       __u64 CurrentMid;         /* multiplex id - rotating counter,
protected by GlobalMid_Lock */
        char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
        /* 16th byte of RFC1001 workstation name is always null */
        char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
@@ -1786,6 +1786,7 @@ require use of the stronger protocol */
  *      updates to XID counters, multiplex id  and SMB sequence numbers
  *      list operations on global DnotifyReqList
  *      updates to ses->status
+ *      updates to server->CurrentMid
  *  tcp_ses_lock protects:
  *     list operations on tcp and SMB session lists
  *  tcon->open_file_lock protects the list of open files hanging off the tcon
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 903de7449aa3..e4c8f603dd58 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -388,7 +388,9 @@ smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
 {
        int rc;

+       spin_lock(&GlobalMid_Lock);
        cifs_ses_server(ses)->CurrentMid = 0;
+       spin_unlock(&GlobalMid_Lock);
        rc = SMB2_negotiate(xid, ses);
        /* BB we probably don't need to retry with modern servers */
        if (rc == -EAGAIN)


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-25 19:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 19:05 [SMB3][PATCH] address minor Coverity warning Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).