Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp833897ybl; Wed, 11 Dec 2019 08:11:46 -0800 (PST) X-Google-Smtp-Source: APXvYqy7Cgjk8fDIxi30xnKCVML2+W0seUPIddxEbE7wcc+rAyrCmlF8QLpcklJ3NMKPgRA8hxkd X-Received: by 2002:aca:3b45:: with SMTP id i66mr2924548oia.5.1576080706595; Wed, 11 Dec 2019 08:11:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080706; cv=none; d=google.com; s=arc-20160816; b=G3ICq+eZzXi3p+JR2OeUGuhNJaNNfUUWWqzYQgzKk/Tg1NyrnlNwl+GYFovq+XzVlO 7iiCSBtIVlR62KRiuQpeB+gsIZKHM0fuicN65YzPAbf9abE5qWd3BHThSJ8cn4jFrgbG Qa5+U/Qk+pSW+Gugx1F9Pv+E1SUPoWXka7mspBCtWjEjTQzj2MIDRkwP+WK3p1L4l6Ud 0/Hgr/kgbMokVgMGy+IZin7rMLQm0J1pX55m6WyQTq/WtBCTOJyHrtb8I1z5MN8mITgs ACYHZyrRVaLwUImTcNTeSJ4MHkhycrz+HSXQBmmh0DNaGCGykBhlydYGlcLS/hNT6kz8 j2uw== 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=/qCWXveSy1MSVQsClo5JfjBhFXBa21ahA499Z/TvWo0=; b=D0p0KL9UjLP/nKhTwO618W6HdMYyTcWr1MI8Hrg/ODTxadeP3EVWy0uCfi4bthBUQ+ DusZtrKIVd/EvolR0HpijkOHDcWi7r0LF8YXEuS8D8IbngivdkGn0eYUZ/Lgrl1FKPHT ijbbRm0HCJzGgidwcR0R4hY80uCqGsaHi0v3KIDF6nNA9L9vYVH9qt7J4Lu+uTKIGy8X JnxXbH1DWasOL5aJYxtts+LzOuWrOw2CljnVBbKuK+5C7N58/puwzUEaVOxVyZKV+NrO m6cN3+yziq23ftS0uPvx20Jcbj68pIVXhg4Gx/lRd/D8KxMEA1b2AV7M7S0lkoRo4C36 UtCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="m4QWtC+/"; 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 q9si1363268oif.92.2019.12.11.08.11.34; Wed, 11 Dec 2019 08:11:46 -0800 (PST) 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="m4QWtC+/"; 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 S2388979AbfLKQK4 (ORCPT + 99 others); Wed, 11 Dec 2019 11:10:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:60642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730328AbfLKPLv (ORCPT ); Wed, 11 Dec 2019 10:11:51 -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 8C4022173E; Wed, 11 Dec 2019 15:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077111; bh=3AC9YLPT4sFT5BYDbu5+f0dgyOFyXPBT2s0ZPrDyeuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4QWtC+/O2UJyMgHS2JdAIQZV6tOLXT9dyuoJJ8OTvKhqHJlWmGA2IkcRAwy8pue7 neejc7q5sEQcKyTb0b2qOYuxVG6aqO4XGzB1ReZG8Kzg6ckwowp9OVHVX3cI5Ir8pU d0K2nwaDevbZ3OCDwgA9+psKY40xN32TwgRIioMc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Sasha Levin Subject: [PATCH 5.3 021/105] exportfs_decode_fh(): negative pinned may become positive without the parent locked Date: Wed, 11 Dec 2019 16:05:10 +0100 Message-Id: <20191211150226.989775102@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 f0e549783caf9..ba6de72a3e34a 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -519,26 +519,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