Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2707306pxv; Sun, 11 Jul 2021 23:21:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfe+lmZ+OuVgA9+2VIVsmCkCOJ5GK29CDARZvQX3WXb68KUH1pC/DQORrrokecVAPlGkP7 X-Received: by 2002:a6b:8b56:: with SMTP id n83mr9757648iod.17.1626070895497; Sun, 11 Jul 2021 23:21:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070895; cv=none; d=google.com; s=arc-20160816; b=cIQvRRG5+9z76ooUG9paJPvgkh9+Q9csS+r0yJs8au2ftr8TGVpMxkiUf38aQq9Ggr lYoKx77BlMm59mOIjZuTFY46iPT8BBMxR6/bW8PE387YN2+HaTLL8+NqsJxMjwuBz4dU 4MR2f+RcqzKtbIEZ8b6zuA7IZHI4j8Q+JzOrofNzkVpiOx6SEFBoMeDLr8AzeG4HTJcU 4IP/T4lYYXIRU9RIXowl2tjI3+4FMJULQfSL/LVzZx+iX6G29pUJt7pIeHCZ6DAEIRSN +ci+DwxGdbY+RZtoFBla8Rajkvw/5fX1En3wWT9n/qVisYzujtNhv1XhF1BrSA7swbWZ vmFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tFRWVjEcox6XpVbEcBWKBm4Suz4D+LVoDgbUNYgSUD4=; b=oCT/evxRqAajOYVJdr+wpok+vbdYS/gHK2maax6PQBR7AF4mK+WeHc9ZXRzCHjnyYy 8bSIdGT6NvbHFSD/85qdAH06cSGClGbKz1dWTGo1e0M+1fcKXt7HHRYqzT2FnwsA1eQw 76vOxXD059VXRndFCXYTSA2eUA7TXKUC9MTuRQj4I2eltNMH+pvh1/X/YYv3iMVanonR 1OFC+HOVuSNClwOStb9kXLFByT9VYaPEiXES/d+YfFEvBAlxnePUvRB4tImMxAr+iXSJ AIKsrhFN7jnrovfhL4xnm83gJ/YXljnHiWu5LVzUGYue9+f8Hmbg8NwMXELgBVBzoLqA 5Azw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UIbyGa2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si18088040ilh.113.2021.07.11.23.21.24; Sun, 11 Jul 2021 23:21:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UIbyGa2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234735AbhGLGXo (ORCPT + 99 others); Mon, 12 Jul 2021 02:23:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:41280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234395AbhGLGWc (ORCPT ); Mon, 12 Jul 2021 02:22:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B4176113A; Mon, 12 Jul 2021 06:19:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070769; bh=lSfJF6GAWok9ndKgaHe/W5GtGfCcKUVUStrb5YyW1GE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UIbyGa2ElLGt/pcSQ4FM0I6HbIPO6CQzaW3Rr6zmVSRzH7s9aJeWzAEYgkbbx7405 zXzxQoaRlHXSLxqIlHJ3SVEtxtB1YtW7mwP0I3afD6BfiocBjqXRD132589r2iRAqM HQjk5RTIdePfXUoy+VbmWXfl4P1v9Qf2lx1zirmM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve French , Sasha Levin Subject: [PATCH 5.4 133/348] cifs: fix missing spinlock around update to ses->status Date: Mon, 12 Jul 2021 08:08:37 +0200 Message-Id: <20210712060718.921117721@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steve French [ Upstream commit 0060a4f28a9ef45ae8163c0805e944a2b1546762 ] In the other places where we update ses->status we protect the updates via GlobalMid_Lock. So to be consistent add the same locking around it in cifs_put_smb_ses where it was missing. Addresses-Coverity: 1268904 ("Data race condition") Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/cifsglob.h | 3 ++- fs/cifs/connect.c | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index b16c994414ab..9c0e348cb00f 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -964,7 +964,7 @@ struct cifs_ses { struct mutex session_mutex; struct TCP_Server_Info *server; /* pointer to server info */ int ses_count; /* reference counter */ - enum statusEnum status; + enum statusEnum status; /* updates protected by GlobalMid_Lock */ unsigned overrideSecFlg; /* if non-zero override global sec flags */ char *serverOS; /* name of operating system underlying server */ char *serverNOS; /* name of network operating system of server */ @@ -1814,6 +1814,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 * tcp_ses_lock protects: * list operations on tcp and SMB session lists * tcon->open_file_lock protects the list of open files hanging off the tcon diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index ab9eeb5ff8e5..da0720f41ebc 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -3049,9 +3049,12 @@ void cifs_put_smb_ses(struct cifs_ses *ses) spin_unlock(&cifs_tcp_ses_lock); return; } + spin_unlock(&cifs_tcp_ses_lock); + + spin_lock(&GlobalMid_Lock); if (ses->status == CifsGood) ses->status = CifsExiting; - spin_unlock(&cifs_tcp_ses_lock); + spin_unlock(&GlobalMid_Lock); cifs_free_ipc(ses); -- 2.30.2