diff mbox series

[CIFS] missing lock when updating session status

Message ID CAH2r5msM9ayyLmijEWjTQJN_kn-gy_Jp5BQRRYuhc-KYqRqYoA@mail.gmail.com
State New
Headers show
Series [CIFS] missing lock when updating session status | expand

Commit Message

Steve French April 27, 2023, 3:09 a.m. UTC
Coverity noted a place where we were not grabbing
the ses_lock when setting (and checking) ses_status.

Addresses-Coverity: 1536833 ("Data race condition (MISSING_LOCK)")

Comments

Steve French April 28, 2023, 4:25 a.m. UTC | #1
lightly updated with Bharath's suggestions of moving cifs_free_ipc()
out of the spinlock

See attached.

On Wed, Apr 26, 2023 at 10:09 PM Steve French <smfrench@gmail.com> wrote:
>
> Coverity noted a place where we were not grabbing
> the ses_lock when setting (and checking) ses_status.
>
> Addresses-Coverity: 1536833 ("Data race condition (MISSING_LOCK)")
>
>
> --
> Thanks,
>
> Steve
diff mbox series

Patch

From 390c90c2928a33f2632e9d668cd3b5b769c9b1e9 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Wed, 26 Apr 2023 22:01:31 -0500
Subject: [PATCH] cifs: missing lock when updating session status

Coverity noted a place where we were not grabbing
the ses_lock when setting (and checking) ses_status.

Addresses-Coverity: 1536833 ("Data race condition (MISSING_LOCK)")
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/connect.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 1cbb90587995..cc538ed61bc0 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1916,19 +1916,22 @@  void cifs_put_smb_ses(struct cifs_ses *ses)
 	/* ses_count can never go negative */
 	WARN_ON(ses->ses_count < 0);
 
+	spin_lock(&ses->ses_lock);
 	if (ses->ses_status == SES_GOOD)
 		ses->ses_status = SES_EXITING;
 
 	cifs_free_ipc(ses);
 
 	if (ses->ses_status == SES_EXITING && server->ops->logoff) {
+		spin_unlock(&ses->ses_lock);
 		xid = get_xid();
 		rc = server->ops->logoff(xid, ses);
 		if (rc)
 			cifs_server_dbg(VFS, "%s: Session Logoff failure rc=%d\n",
 				__func__, rc);
 		_free_xid(xid);
-	}
+	} else
+		spin_unlock(&ses->ses_lock);
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_del_init(&ses->smb_ses_list);
-- 
2.34.1