From patchwork Tue Apr 28 12:46:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Bo X-Patchwork-Id: 11514441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A931F14B4 for ; Tue, 28 Apr 2020 12:47:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CBD3206F0 for ; Tue, 28 Apr 2020 12:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726827AbgD1MrN (ORCPT ); Tue, 28 Apr 2020 08:47:13 -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 X-Originating-IP: [10.175.105.27] X-CFilter-Loop: Reflected Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@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: