Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4126240ybz; Tue, 28 Apr 2020 06:16:31 -0700 (PDT) X-Google-Smtp-Source: APiQypLoKPNlV9Z1Ds2Wd11+/9QHha+uIDuu+XeQU1wvGKhD6u+CX/Yn71+JmZptD9B2dCsA9lUl X-Received: by 2002:a50:8dc2:: with SMTP id s2mr7194721edh.318.1588079791498; Tue, 28 Apr 2020 06:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588079791; cv=none; d=google.com; s=arc-20160816; b=LLVES8SJGIcZyLisYqGsBI2/er1/F9JRfZiVqA/l7c/jgYHkTvOoPTye9cX3THY6O5 HQ8TDknEaR6dWOkmUoj2oUxPMKVl75XrKvmpFJMs35QxMaDr7hj5fe3xIuJMZhlikAow wOYPejVI0fqOXcQv4f950AnvTiVBprungtrUZCjzaDWiOl6ZHjniaQIXFOCx7cPuQnK3 ucakX9eiiBzdaDGN+bNb1tlx0ONIIunThCCopb4A9+zBPlnclEBXDRre1OUaPmODj+lC xooZd+W0caGLL1RKb3i7CnwhXY1eoJ8eu784LBBS5dKMEjfebsuYvbY2mtOZo6aGCfwN mqzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=mgD/7upXMOa+eq6+JuqWjvQU52kaaLKhgXIcjT8z4zw=; b=CLCohNFbcMZuGKVq/2ohBlI1oUU63HIoMlP9tXUYADhgZ0S4pp/cH4DeBJeZqG0TJP gb76kn5VBoJFQoP8/Xib7Do0V5Oc77Gua9KCpgnoZMwybjQDzkw7TRgEhcxDfYx89NsC Ty3V+ZrDs6XjJ/ioNnG+f28p5nKQrM30nX/wpBTDSIEbfpQJ3Q3cLEAzieuMsYIK6l5s bZ2QOwzO7U1DE/NMt7tWJhH7t1VJ7tzfEwThrOgXJWoq3iPRDhSrbInHVuBjIgc0RSGX n0BilvrsUCdC2vOiQmRGwaV+p8PPm/b5hIqkihaNVNCM8OiouM/1/uK0cpkrBc0THQFZ kw1w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y20si1926363eje.323.2020.04.28.06.16.08; Tue, 28 Apr 2020 06:16:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726940AbgD1NOu (ORCPT + 99 others); Tue, 28 Apr 2020 09:14:50 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:53036 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726764AbgD1NOt (ORCPT ); Tue, 28 Apr 2020 09:14:49 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E60FA5E7908F185C8AFE; Tue, 28 Apr 2020 21:14:47 +0800 (CST) Received: from huawei.com (10.175.105.27) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Tue, 28 Apr 2020 21:14:37 +0800 From: Wu Bo To: , , CC: , , , , Subject: [PATCH V2] fs/ceph:fix double unlock in handle_cap_export() Date: Tue, 28 Apr 2020 21:13:42 +0800 Message-ID: <1588079622-423774-1-git-send-email-wubo40@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.105.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org if the ceph_mdsc_open_export_target_session() return fails, should add a lock to avoid twice unlocking. Because the lock will be released at the retry or out_unlock tag. -- v1 -> v2: add spin_lock(&ci->i_ceph_lock) before goto out_unlock tag. Signed-off-by: Wu Bo --- fs/ceph/caps.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 185db76..414c0e2 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -3731,22 +3731,25 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, /* open target session */ tsession = ceph_mdsc_open_export_target_session(mdsc, target); - if (!IS_ERR(tsession)) { - if (mds > target) { - mutex_lock(&session->s_mutex); - mutex_lock_nested(&tsession->s_mutex, - SINGLE_DEPTH_NESTING); - } else { - mutex_lock(&tsession->s_mutex); - mutex_lock_nested(&session->s_mutex, - SINGLE_DEPTH_NESTING); - } - new_cap = ceph_get_cap(mdsc, NULL); - } else { + if (IS_ERR(tsession)) { WARN_ON(1); tsession = NULL; target = -1; + mutex_lock(&session->s_mutex); + spin_lock(&ci->i_ceph_lock); + goto out_unlock; + } + + if (mds > target) { + mutex_lock(&session->s_mutex); + mutex_lock_nested(&tsession->s_mutex, + SINGLE_DEPTH_NESTING); + } else { + mutex_lock(&tsession->s_mutex); + mutex_lock_nested(&session->s_mutex, + SINGLE_DEPTH_NESTING); } + new_cap = ceph_get_cap(mdsc, NULL); goto retry; out_unlock: -- 1.8.3.1