diff mbox series

[SMB3,client] missing lock when picking channel

Message ID CAH2r5ms2xmxgZ08pecifj+Za=_oWnrhVOUgifjYLnCw+Rz9_kA@mail.gmail.com (mailing list archive)
State New, archived
Headers show
Series [SMB3,client] missing lock when picking channel | expand

Commit Message

Steve French April 25, 2024, 4:44 p.m. UTC
Coverity spotted a place where we should have been holding the
channel lock when accessing the ses channel index.

Addresses-Coverity: 1582039 ("Data race condition (MISSING_LOCK)")
Cc: stable@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/smb/client/transport.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Shyam Prasad N April 25, 2024, 4:55 p.m. UTC | #1
On Thu, Apr 25, 2024 at 10:14 PM Steve French <smfrench@gmail.com> wrote:
>
> Coverity spotted a place where we should have been holding the
> channel lock when accessing the ses channel index.
>
> Addresses-Coverity: 1582039 ("Data race condition (MISSING_LOCK)")
> Cc: stable@vger.kernel.org
> Signed-off-by: Steve French <stfrench@microsoft.com>
> ---
>  fs/smb/client/transport.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
> index 443b4b89431d..fc0ddc75abc9 100644
> --- a/fs/smb/client/transport.c
> +++ b/fs/smb/client/transport.c
> @@ -1059,9 +1059,11 @@ struct TCP_Server_Info
> *cifs_pick_channel(struct cifs_ses *ses)
>   index = (uint)atomic_inc_return(&ses->chan_seq);
>   index %= ses->chan_count;
>   }
> +
> + server = ses->chans[index].server;
>   spin_unlock(&ses->chan_lock);
>
> - return ses->chans[index].server;
> + return server;
>  }
>
> --
> Thanks,
>
> Steve

Looks good to me.
Meetakshi Setiya April 26, 2024, 6:46 a.m. UTC | #2
Looks good

Thanks
Meetakshi

On Thu, Apr 25, 2024 at 10:14 PM Steve French <smfrench@gmail.com> wrote:
>
> Coverity spotted a place where we should have been holding the
> channel lock when accessing the ses channel index.
>
> Addresses-Coverity: 1582039 ("Data race condition (MISSING_LOCK)")
> Cc: stable@vger.kernel.org
> Signed-off-by: Steve French <stfrench@microsoft.com>
> ---
>  fs/smb/client/transport.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
> index 443b4b89431d..fc0ddc75abc9 100644
> --- a/fs/smb/client/transport.c
> +++ b/fs/smb/client/transport.c
> @@ -1059,9 +1059,11 @@ struct TCP_Server_Info
> *cifs_pick_channel(struct cifs_ses *ses)
>   index = (uint)atomic_inc_return(&ses->chan_seq);
>   index %= ses->chan_count;
>   }
> +
> + server = ses->chans[index].server;
>   spin_unlock(&ses->chan_lock);
>
> - return ses->chans[index].server;
> + return server;
>  }
>
> --
> Thanks,
>
> Steve
diff mbox series

Patch

From 5ec995c33cc30f1cfb26ab0126c077ca82f64a06 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Thu, 25 Apr 2024 11:30:16 -0500
Subject: [PATCH 2/2] smb3: missing lock when picking channel

Coverity spotted a place where we should have been holding the
channel lock when accessing the ses channel index.

Addresses-Coverity: 1582039 ("Data race condition (MISSING_LOCK)")
Cc: stable@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/smb/client/transport.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
index 443b4b89431d..fc0ddc75abc9 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -1059,9 +1059,11 @@  struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses)
 		index = (uint)atomic_inc_return(&ses->chan_seq);
 		index %= ses->chan_count;
 	}
+
+	server = ses->chans[index].server;
 	spin_unlock(&ses->chan_lock);
 
-	return ses->chans[index].server;
+	return server;
 }
 
 int
-- 
2.40.1