Skip to contentSkip to conversation

smb: fix a possible data race in cifs_can_echo()

PATCH Superseded Tuo Li 1 participant 1 message Jun 15, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 smb: fix a possible data race in cifs_can_echo()

The struct field TCP_Server_Info.tcpStatus is often protected by the lock srv_lock when is accessed. Here is an example in __cifs_reconnect():

  spin_lock(&server->srv_lock);
  if (server->tcpStatus != CifsExiting)
    server->tcpStatus = CifsNeedNegotiate;
  spin_unlock(&server->srv_lock);

However, the variable server->tcpStatus is accessed without holding the lock server->srv_lock in cifs_can_echo():

if (server->tcpStatus == CifsGood)

    return true;

To fix this possible data race, a lock and unlock pair is added when accessing the variable server->tcpStatus.

---
 fs/smb/client/smb1ops.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/smb/client/smb1ops.c +4 -1
index 7d1b3fc014d9..b258af1a75fe 100644
@@ -1049,8 +1049,11 @@ cifs_dir_needs_close(struct cifsFileInfo *cfile)
 static bool
 cifs_can_echo(struct TCP_Server_Info *server)
 {
-	if (server->tcpStatus == CifsGood)
+	spin_lock(&server->srv_lock);
+	if (server->tcpStatus == CifsGood) {
+		spin_unlock(&server->srv_lock);
 		return true;
+	}
 
 	return false;
 }
Signature · 1 line
2.34.1