Received: by 10.213.65.68 with SMTP id h4csp246391imn; Fri, 23 Mar 2018 03:50:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELuPQrReGj5c/5zRdUodqq7eXuxi8O4T+zp/EP+XiGevqiTOmkXsbGH8AJEQf0lE3hYXsxUp X-Received: by 10.99.97.143 with SMTP id v137mr20325259pgb.175.1521802251217; Fri, 23 Mar 2018 03:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521802251; cv=none; d=google.com; s=arc-20160816; b=e8ynK1H/etETgSC7kDN1Ax5JmQa5KZLplRjoz9+leGDnp/R+tqXAqqHgxwLP3gGBP+ cqoGBc3nDpoSgSUYZEZ+pbORBa+nAJaqi6rXGZevfEBG8lMzxZti7Z1hhFLQT1JYAfmz fPPk6qqF1iMoyFBpKKeFGQyoF/PqDzCnX9j1vbLSZJnRug+Q+RNgICy3P9xZZbpLd3Sm q0JzR+0DI1pjaGeldEnaXJHGNLqttqCiu2UYaEKixdP0eayScx5PoG0mX7yjmvFoPfvA bBYGsEqvO7ekgJtSsYNhVktoEgkomcJ96yZzwMGHJA0ZWrQ4Kv8w1ESMxAO6xq53FWTG Ptgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8Xw8b92N97xANLFJyW4txNvaHQi3cWG4SP24m9+q144=; b=xrLqzdp8PRYqyunTknrhs4qBGd7R6XZB494CeJ3XqAChOCVgW7Bxolf5qp+5RIRWGg z1pPl8DWCOV1CPeDgE4qiMxzdS7XO7HFaIvO8JrwWMZfPxUJukq/4OP1gs0hS/DEeGaM ek0iOWUhiRnPUqt3JIdqV2z6mX0WTwWJCsq5tYoDQNRrMpSEdAou3BxVM+SNsFqb9JKj UmaAXUancpEZwS/Jh02Ha2AHt69TgWoQxdE4QIjAeqnE+SOCOdEpnlDFhCW22ikPHGkL ZoWg6VBEmM4HzGVrI8eoH3uWNNplBi/7f+ZyzjepP3JrOIaDZdUZ+xFAwRPoiN7x0k7U KwtA== ARC-Authentication-Results: i=1; mx.google.com; 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 o16si5709402pgc.832.2018.03.23.03.50.36; Fri, 23 Mar 2018 03:50:51 -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; 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 S1756111AbeCWKtb (ORCPT + 99 others); Fri, 23 Mar 2018 06:49:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45378 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933376AbeCWKOt (ORCPT ); Fri, 23 Mar 2018 06:14:49 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 608A0119C; Fri, 23 Mar 2018 10:14:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , "J. Bruce Fields" , Sasha Levin Subject: [PATCH 4.4 45/97] NFS: dont try to cross a mountpount when there isnt one there. Date: Fri, 23 Mar 2018 10:54:32 +0100 Message-Id: <20180323094200.159240849@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: NeilBrown [ Upstream commit 99bbf6ecc694dfe0b026e15359c5aa2a60b97a93 ] consider the sequence of commands: mkdir -p /import/nfs /import/bind /import/etc mount --bind / /import/bind mount --make-private /import/bind mount --bind /import/etc /import/bind/etc exportfs -o rw,no_root_squash,crossmnt,async,no_subtree_check localhost:/ mount -o vers=4 localhost:/ /import/nfs ls -l /import/nfs/etc You would not expect this to report a stale file handle. Yet it does. The manipulations under /import/bind cause the dentry for /etc to get the DCACHE_MOUNTED flag set, even though nothing is mounted on /etc. This causes nfsd to call nfsd_cross_mnt() even though there is no mountpoint. So an upcall to mountd for "/etc" is performed. The 'crossmnt' flag on the export of / causes mountd to report that /etc is exported as it is a descendant of /. It assumes the kernel wouldn't ask about something that wasn't a mountpoint. The filehandle returned identifies the filesystem and the inode number of /etc. When this filehandle is presented to rpc.mountd, via "nfsd.fh", the inode cannot be found associated with any name in /etc/exports, or with any mountpoint listed by getmntent(). So rpc.mountd says the filehandle doesn't exist. Hence ESTALE. This is fixed by teaching nfsd not to trust DCACHE_MOUNTED too much. It is just a hint, not a guarantee. Change nfsd_mountpoint() to return '1' for a certain mountpoint, '2' for a possible mountpoint, and 0 otherwise. Then change nfsd_crossmnt() to check if follow_down() actually found a mountpount and, if not, to avoid performing a lookup if the location is not known to certainly require an export-point. Signed-off-by: NeilBrown Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/vfs.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -92,6 +92,12 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, s err = follow_down(&path); if (err < 0) goto out; + if (path.mnt == exp->ex_path.mnt && path.dentry == dentry && + nfsd_mountpoint(dentry, exp) == 2) { + /* This is only a mountpoint in some other namespace */ + path_put(&path); + goto out; + } exp2 = rqst_exp_get_by_name(rqstp, &path); if (IS_ERR(exp2)) { @@ -165,16 +171,26 @@ static int nfsd_lookup_parent(struct svc /* * For nfsd purposes, we treat V4ROOT exports as though there was an * export at *every* directory. + * We return: + * '1' if this dentry *must* be an export point, + * '2' if it might be, if there is really a mount here, and + * '0' if there is no chance of an export point here. */ int nfsd_mountpoint(struct dentry *dentry, struct svc_export *exp) { - if (d_mountpoint(dentry)) + if (!d_inode(dentry)) + return 0; + if (exp->ex_flags & NFSEXP_V4ROOT) return 1; if (nfsd4_is_junction(dentry)) return 1; - if (!(exp->ex_flags & NFSEXP_V4ROOT)) - return 0; - return d_inode(dentry) != NULL; + if (d_mountpoint(dentry)) + /* + * Might only be a mountpoint in a different namespace, + * but we need to check. + */ + return 2; + return 0; } __be32