Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9936693ybi; Wed, 24 Jul 2019 12:38:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfb+XlVECGjL8eSSvBWQfVu6PPdJSpKMfYdlX/01pV9Z6JafkzjXsr57/4mzFbAjimWpGt X-Received: by 2002:a17:902:8a87:: with SMTP id p7mr86879713plo.124.1563997134336; Wed, 24 Jul 2019 12:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563997134; cv=none; d=google.com; s=arc-20160816; b=XgvDzxaH6cX1NOMLH6KeD47RJhh0PnzW7inrICqdU5FQmEJjQlvw9GkUOtbhMOfTIm 15atga9wamdGMSBIk/fXHFMqAiVsb4GhVK3axirYCOnk32DJwZbSWooHh4I5nld5H6cT /z8mA9Bs7TIycxyN2i6LZaUK4VH+NrPCvc49747xjN4sbUuo4AuZzokTDI1Wi1nnV93G X/10W6coHRtBzAJ3/7gkl23Lo6YACzikitk2NrgU/7dbDdfI4k3p1Zph06bB/nwnVdSj xf6OKQ9FnGbiVkR5Nm7e3dMN5Nlwi6S1ETF1w9GjtOfIbhCJKUfeWjfydbn6xBsIz1uw R5rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x1u/9KiW2BwCx7kxuukGOunZPHl4Eo1bToURTYKXFGg=; b=BWep7dZJPiu/6eTVvy5tSdRfmTvk7CRrh4mHLkIR4CgCJlpJgT1lVjzHL4o5HX+eJ5 NOZv3nEWQ0nzZlVS9fINeqBSXgssCdaoedkrlgLTuhJZb+Vd33xZXM761iWx/isYecda l8FxWIcouRP8jZe2rJxlqIsxSIEv9465kpxSZtFQNrweA29nLBo2NwHNM1yAJ+dubLwb 19DXl6GXJuGR6xIVORkR6Fme57rYtDuWn6rI49xSMWUb4g5Updi6mUUOmwt1GjkzNhmF L2av1w5u8fElS0xYRbRwXnsRFZIN6vCdHByi+xsMOAAK5xsFTI/E+N/GQMJFsSa20uQy Lb7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="sOA6/cgT"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si14065368plk.388.2019.07.24.12.38.39; Wed, 24 Jul 2019 12:38:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="sOA6/cgT"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389300AbfGXTgP (ORCPT + 99 others); Wed, 24 Jul 2019 15:36:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:35836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389289AbfGXTgN (ORCPT ); Wed, 24 Jul 2019 15:36:13 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3C50A229F3; Wed, 24 Jul 2019 19:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996971; bh=OR9DaQIEQw3qnxF0j8VZbZv+NIuXumN8R7MCJwQNeYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sOA6/cgTVIS1yciJgCOt/qBTs+TpsIo2R3Vv/eim8PnmJ/VWqPqJzURXOFSZgT3Eb pB79rosTu7HsoaWeXz91bOkmfM58U8m0iFmPx4PjgECDwK2M2ZyDwqePrU4K6Tuf7t rrYGNKBh0YBOKedAUDvVgDOtLASNnVS/sSU/01rk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aurelien Aptel , Pavel Shilovsky , Steve French Subject: [PATCH 5.2 279/413] CIFS: fix deadlock in cached root handling Date: Wed, 24 Jul 2019 21:19:30 +0200 Message-Id: <20190724191756.262519456@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aurelien Aptel commit 7e5a70ad88b1e6f6d9b934b2efb41afff496820f upstream. Prevent deadlock between open_shroot() and cifs_mark_open_files_invalid() by releasing the lock before entering SMB2_open, taking it again after and checking if we still need to use the result. Link: https://lore.kernel.org/linux-cifs/684ed01c-cbca-2716-bc28-b0a59a0f8521@prodrive-technologies.com/T/#u Fixes: 3d4ef9a15343 ("smb3: fix redundant opens on root") Signed-off-by: Aurelien Aptel Reviewed-by: Pavel Shilovsky Signed-off-by: Steve French CC: Stable Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -694,8 +694,51 @@ int open_shroot(unsigned int xid, struct smb2_set_related(&rqst[1]); + /* + * We do not hold the lock for the open because in case + * SMB2_open needs to reconnect, it will end up calling + * cifs_mark_open_files_invalid() which takes the lock again + * thus causing a deadlock + */ + + mutex_unlock(&tcon->crfid.fid_mutex); rc = compound_send_recv(xid, ses, flags, 2, rqst, resp_buftype, rsp_iov); + mutex_lock(&tcon->crfid.fid_mutex); + + /* + * Now we need to check again as the cached root might have + * been successfully re-opened from a concurrent process + */ + + if (tcon->crfid.is_valid) { + /* work was already done */ + + /* stash fids for close() later */ + struct cifs_fid fid = { + .persistent_fid = pfid->persistent_fid, + .volatile_fid = pfid->volatile_fid, + }; + + /* + * caller expects this func to set pfid to a valid + * cached root, so we copy the existing one and get a + * reference. + */ + memcpy(pfid, tcon->crfid.fid, sizeof(*pfid)); + kref_get(&tcon->crfid.refcount); + + mutex_unlock(&tcon->crfid.fid_mutex); + + if (rc == 0) { + /* close extra handle outside of crit sec */ + SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); + } + goto oshr_free; + } + + /* Cached root is still invalid, continue normaly */ + if (rc) goto oshr_exit; @@ -729,8 +772,9 @@ int open_shroot(unsigned int xid, struct (char *)&tcon->crfid.file_all_info)) tcon->crfid.file_all_info_is_valid = 1; - oshr_exit: +oshr_exit: mutex_unlock(&tcon->crfid.fid_mutex); +oshr_free: SMB2_open_free(&rqst[0]); SMB2_query_info_free(&rqst[1]); free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);