Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4096713ybz; Tue, 28 Apr 2020 05:49:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJzh8dV3iM+csJfTECrEWYOXvrcOhsrMEFeCKe2TRYk2mlTIHcFqoA5TZ/6jVRXUKJJQ4aI X-Received: by 2002:a17:906:5fd2:: with SMTP id k18mr23940453ejv.243.1588078152037; Tue, 28 Apr 2020 05:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588078152; cv=none; d=google.com; s=arc-20160816; b=BK+mX/1tyqMplar/hgQSQvBAX+HJoDlFRIjb+5FVRSku4Ypt5iOFFG/VwKLewYVYXQ y4GaMuTceCeK09Cud0gIN7ZnYWNlwvVciI9lJJvggNRQj8FP9qkyPydOUREa3tlA4bjc sld1fZzAYeDeRjGJ87TdngwPlBfU+TeTfjaVxnCvqL9Tt8JKMwJQM2z8uIkIeKaAhob2 dN+G/5J+QRgVj0KNkkGofUjYZs9q9XB1lUQcizMu8Th680x8oIfhCkIEasxKnbHWakm9 IpgqW+gRd0TlWAw+1VcQP/0laiexbzDDbv04Xe/qHnXrjhjARPlm0SqMrO4CDvsymj/C 90sg== 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=O9ThtJm1rf6dwRz+qLx3Gtcg3rK1MCO+QHb0DorxoL0=; b=MMoL5bq4rUlsaYrUFdaCZGdA9xcUQ0OTDI/accUywd4l3p599Bxc2Y0nymt8A1XKFA Pg0Sivq5zwcT3Wott4dTc0cgOZvmIyPkCx3dSdb+ZTg22PtBaS/DfaXCbwZZrcdHt4+V ddtCa0uml8ZPrsl4C+fMz9M1p3S+ePzS/N0fcuGUIqJKLgvfmqWbWz6xDVe8CFvXdA+p ZpnfJxzUlT3CZdEyYL8OG9FjzKLNzHCdNgI8/4AsCqb+kyFVgmS/nKowpIEyOpC6vWKq ySBlTrCLc8mmtjklb3n+S2UtJnhGb5r3fwz4Xg7+SEIvOEp6eZBWKz49s2jHciwVUCxA 9jiA== 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 bd19si1584439edb.28.2020.04.28.05.48.48; Tue, 28 Apr 2020 05:49:12 -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 S1726891AbgD1MrO (ORCPT + 99 others); Tue, 28 Apr 2020 08:47:14 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:53584 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726620AbgD1MrM (ORCPT ); Tue, 28 Apr 2020 08:47:12 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 39AEF243388146992167; Tue, 28 Apr 2020 20:47:07 +0800 (CST) Received: from huawei.com (10.175.105.27) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Tue, 28 Apr 2020 20:46:56 +0800 From: Wu Bo To: , , CC: , , , , Subject: [PATCH] fs/ceph:fix double unlock in handle_cap_export() Date: Tue, 28 Apr 2020 20:46:02 +0800 Message-ID: <1588077962-353994-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. Signed-off-by: Wu Bo --- fs/ceph/caps.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 185db76..b5a62a8 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -3731,22 +3731,24 @@ 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); + 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