From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCE76C43603 for ; Wed, 11 Dec 2019 15:16:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 835D32465E for ; Wed, 11 Dec 2019 15:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077376; bh=1onni7qI1StNp13OOOaMTO2TDuBSUXH5Q66vVgyAGyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DuH/8x/Zg/SeIVIg8hgcWpgoTXbkQAA6jDtSc4pMYwfMwkOyXkAfSuCisO6niVmK0 z0nFttveN+IHp1QlOqoDmqRWbf1mfbkoVKhLIKLdO4bGirP0A6aIIyiuLvLkQzzesO Y7ZEKurionq/bU8cf770KtItJ4l7HuXpU10rSDbA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731873AbfLKPQP (ORCPT ); Wed, 11 Dec 2019 10:16:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:43104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730625AbfLKPQL (ORCPT ); Wed, 11 Dec 2019 10:16:11 -0500 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 76D1524658; Wed, 11 Dec 2019 15:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077370; bh=1onni7qI1StNp13OOOaMTO2TDuBSUXH5Q66vVgyAGyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0MCVcNYhJSMJbuemar0FLbKGl+n4jzJyZUEBtcY1tDC+YUnFJT190D7p1L4yNmNv4 ueHFBbnwcvtcq3LFga+E+FhK+Y2gV1wHK4WCjStsR5v2/MGm2jYbj8GeTKQ0oicjeI o234bY2CAhB2Qv6TXVK9yL/8qFw/JN2CTqyBHnXo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Sasha Levin Subject: [PATCH 4.19 014/243] exportfs_decode_fh(): negative pinned may become positive without the parent locked Date: Wed, 11 Dec 2019 16:02:56 +0100 Message-Id: <20191211150340.026235184@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@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: Al Viro [ Upstream commit a2ece088882666e1dc7113744ac912eb161e3f87 ] Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/exportfs/expfs.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index 63707abcbeb3e..808cae6d5f50f 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -517,26 +517,33 @@ struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid, * inode is actually connected to the parent. */ err = exportfs_get_name(mnt, target_dir, nbuf, result); - if (!err) { - inode_lock(target_dir->d_inode); - nresult = lookup_one_len(nbuf, target_dir, - strlen(nbuf)); - inode_unlock(target_dir->d_inode); - if (!IS_ERR(nresult)) { - if (nresult->d_inode) { - dput(result); - result = nresult; - } else - dput(nresult); - } + if (err) { + dput(target_dir); + goto err_result; } + inode_lock(target_dir->d_inode); + nresult = lookup_one_len(nbuf, target_dir, strlen(nbuf)); + if (!IS_ERR(nresult)) { + if (unlikely(nresult->d_inode != result->d_inode)) { + dput(nresult); + nresult = ERR_PTR(-ESTALE); + } + } + inode_unlock(target_dir->d_inode); /* * At this point we are done with the parent, but it's pinned * by the child dentry anyway. */ dput(target_dir); + if (IS_ERR(nresult)) { + err = PTR_ERR(nresult); + goto err_result; + } + dput(result); + result = nresult; + /* * And finally make sure the dentry is actually acceptable * to NFSD. -- 2.20.1