From patchwork Thu Jul 1 17:28:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12354609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89FF6C11F64 for ; Thu, 1 Jul 2021 17:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6385261407 for ; Thu, 1 Jul 2021 17:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229987AbhGARbT (ORCPT ); Thu, 1 Jul 2021 13:31:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbhGARbS (ORCPT ); Thu, 1 Jul 2021 13:31:18 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262CCC061762 for ; Thu, 1 Jul 2021 10:28:47 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id p24so9582847ljj.1 for ; Thu, 01 Jul 2021 10:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=sUKTCKGOlEVhngMnwQAbfvnc7VUhol/h9zwsDZ/ptLc=; b=S3j5njcQpzsBRPs8O/APU9P6e2Q+LGyEeMqBc5pIKwkyPKB0z9hKiRwiNPXJNzJ4az 8PvpSOnGoWGDmgAnk5rgIxvVAOLUKHfKhaDn5Xn21lkcbM7fJcoaLx1hLdTn0My6jb/o xF1RAc0e4hmwI1dc17T4/IxzCTyVa7EMoXJC4z/YDsUzJ5LNUSaFD8gYB8KyRfAsMHbb 4KzbduL5RQMuPfenIG4i7dPGkcyq/KYsghLI0dZFUV1LCYawbuelIkmjJotHJeT0mTJF pBIxr8TiJkAyOJn0jvAPExeXMmXvLDM5q5oWNfPUI+DLIjiGwepO9twTYlJW2ItG3BF8 wFOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=sUKTCKGOlEVhngMnwQAbfvnc7VUhol/h9zwsDZ/ptLc=; b=hZu/MOEUI3A6vj+kPBkPPvvByUXv9NcG1MumfsoqzFsHs1JAhvFj7H/DRcVE3ooGW4 vSgtIkBtFwvGzDIKVdc0rKBmBZ79ihzDbwrq8URiA343Si8gtAsVkRc0fLuaKP5ALdBe ocnyzv+D/dhzFcjlTDQSR4Yoc7dU4o94zMMUEMYcdgFyf/svtgIKSIq25wq2aLTybIDa /MvRUo6cM8wH3blfwJMHpmccDXYw8PExHsZUhmRKSedz8k8tiGM0sqTpLvFS/uW4g7ET vSzgI75QT+i+mSzFnQzUjspcLqnY26VbNXouFyj4AdrgZKsT7xfW3KoD2gPgqJfU/e/Z pqYg== X-Gm-Message-State: AOAM531hDJqn2XsIs09fbWu/bN7sRq+WKBeHPnOqPLQL0Yei7NmXNcMJ 7KktWHnw5PnyhJbv3Wh1ZxOXpsA4qTED9YYeXCalwvgOf02A/A== X-Google-Smtp-Source: ABdhPJzztH/Q9xPPGGVYS3tPbOBZiPKv3i8zaxK6D+WlnUtrCBsheeyl/QlnbkCJ4JyciMGsOKF6cRQwVgm9E69LsM8= X-Received: by 2002:a2e:960e:: with SMTP id v14mr547329ljh.148.1625160524625; Thu, 01 Jul 2021 10:28:44 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Thu, 1 Jul 2021 12:28:33 -0500 Message-ID: Subject: [PATCH][CIFS] make locking consistent around the server session status To: CIFS Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org There were three places where we were not taking the spinlock around updates to server->tcpStatus when it was being modified. To be consistent (also removes Coverity warning) and to remove possibility of race best to lock all places where it is updated. Addresses-Coverity: 1399512 ("Data race condition") Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 3 ++- fs/cifs/connect.c | 4 ++++ fs/cifs/transport.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) } From dc43ee1df9b95c4d9e17285926d64c4600340f1e Mon Sep 17 00:00:00 2001 From: Steve French Date: Thu, 1 Jul 2021 12:22:47 -0500 Subject: [PATCH] cifs: make locking consistent around the server session status There were three places where we were not taking the spinlock around updates to server->tcpStatus when it was being modified. To be consistent (also removes Coverity warning) and to remove possibility of race best to lock all places where it is updated. Addresses-Coverity: 1399512 ("Data race condition") Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 3 ++- fs/cifs/connect.c | 4 ++++ fs/cifs/transport.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 3100f8b66e60..921680fb7931 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -577,6 +577,7 @@ struct TCP_Server_Info { char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; struct smb_version_operations *ops; struct smb_version_values *vals; + /* updates to tcpStatus protected by GlobalMid_Lock */ enum statusEnum tcpStatus; /* what we think the status is */ char *hostname; /* hostname portion of UNC string */ struct socket *ssocket; @@ -1785,7 +1786,7 @@ require use of the stronger protocol */ * list operations on pending_mid_q and oplockQ * updates to XID counters, multiplex id and SMB sequence numbers * list operations on global DnotifyReqList - * updates to ses->status + * updates to ses->status and TCP_Server_Info->tcpStatus * updates to server->CurrentMid * tcp_ses_lock protects: * list operations on tcp and SMB session lists diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 5d269f583dac..944fb92f50c7 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1358,7 +1358,9 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx) * to the struct since the kernel thread not created yet * no need to spinlock this init of tcpStatus or srv_count */ + spin_lock(&GlobalMid_Lock); tcp_ses->tcpStatus = CifsNew; + spin_unlock(&GlobalMid_Lock); ++tcp_ses->srv_count; if (ctx->echo_interval >= SMB_ECHO_INTERVAL_MIN && @@ -1403,7 +1405,9 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx) goto out_err_crypto_release; } tcp_ses->min_offload = ctx->min_offload; + spin_lock(&GlobalMid_Lock); tcp_ses->tcpStatus = CifsNeedNegotiate; + spin_unlock(&GlobalMid_Lock); if ((ctx->max_credits < 20) || (ctx->max_credits > 60000)) tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE; diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index f65f9a692ca2..75a95de320cf 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -431,7 +431,9 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, * be taken as the remainder of this one. We need to kill the * socket so the server throws away the partial SMB */ + spin_lock(&GlobalMid_Lock); server->tcpStatus = CifsNeedReconnect; + spin_unlock(&GlobalMid_Lock); trace_smb3_partial_send_reconnect(server->CurrentMid, server->conn_id, server->hostname); } -- 2.30.2