diff mbox series

[v2,2/3] smb: client: Protect tcon->status with tc_lock spin lock

Message ID 1f2c738ab53d6aa430001b5847feee0f73dd51c4.1701062286.git.pierre.mariani@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/3] smb: client: Protect ses->chans update with chan_lock spin lock | expand

Commit Message

Pierre Mariani Nov. 27, 2023, 5:22 a.m. UTC
Protect the update of tcon->status with tc_lock spin lock as per documentation
from cifsglob.h.
Fixes Coverity 1560722 Data race condition.

Signed-off-by: Pierre Mariani <pierre.mariani@gmail.com>
---
 fs/smb/client/connect.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Steve French Jan. 9, 2024, 11:44 p.m. UTC | #1
presumably this is unneeded since in this code path we are
initializing - we have a newly allocated tcon which hasn't been
returned to anyone yet so no other threads could update those fields
(until e.g. worker threads or launched which doesn't happen until a
few lines lower, or the tcon returned)

On Sun, Nov 26, 2023 at 11:23 PM Pierre Mariani
<pierre.mariani@gmail.com> wrote:
>
> Protect the update of tcon->status with tc_lock spin lock as per documentation
> from cifsglob.h.
> Fixes Coverity 1560722 Data race condition.
>
> Signed-off-by: Pierre Mariani <pierre.mariani@gmail.com>
> ---
>  fs/smb/client/connect.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
> index f7d436daaa80..26e3eeda0c4c 100644
> --- a/fs/smb/client/connect.c
> +++ b/fs/smb/client/connect.c
> @@ -2711,7 +2711,9 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
>         tcon->nodelete = ctx->nodelete;
>         tcon->local_lease = ctx->local_lease;
>         INIT_LIST_HEAD(&tcon->pending_opens);
> +       spin_lock(&tcon->tc_lock);
>         tcon->status = TID_GOOD;
> +       spin_unlock(&tcon->tc_lock);
>
>         INIT_DELAYED_WORK(&tcon->query_interfaces,
>                           smb2_query_server_interfaces);
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index f7d436daaa80..26e3eeda0c4c 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -2711,7 +2711,9 @@  cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
 	tcon->nodelete = ctx->nodelete;
 	tcon->local_lease = ctx->local_lease;
 	INIT_LIST_HEAD(&tcon->pending_opens);
+	spin_lock(&tcon->tc_lock);
 	tcon->status = TID_GOOD;
+	spin_unlock(&tcon->tc_lock);
 
 	INIT_DELAYED_WORK(&tcon->query_interfaces,
 			  smb2_query_server_interfaces);