aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/vfs.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2017-03-14 21:40:44 -0400
committerJ. Bruce Fields <bfields@redhat.com>2017-04-25 17:25:54 -0400
commit99bbf6ecc694dfe0b026e15359c5aa2a60b97a93 (patch)
tree2b58d5702d17326f54995cadb8d5b2f9c635da5c /fs/nfsd/vfs.c
parent2f10fdcb6a1c5f26246339d3b606131fae483c44 (diff)
NFS: don't try to cross a mountpount when there isn't one there.
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 <neilb@suse.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd/vfs.c')
-rw-r--r--fs/nfsd/vfs.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 19d50f600e8d..04cafaa94bf7 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -94,6 +94,12 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
94 err = follow_down(&path); 94 err = follow_down(&path);
95 if (err < 0) 95 if (err < 0)
96 goto out; 96 goto out;
97 if (path.mnt == exp->ex_path.mnt && path.dentry == dentry &&
98 nfsd_mountpoint(dentry, exp) == 2) {
99 /* This is only a mountpoint in some other namespace */
100 path_put(&path);
101 goto out;
102 }
97 103
98 exp2 = rqst_exp_get_by_name(rqstp, &path); 104 exp2 = rqst_exp_get_by_name(rqstp, &path);
99 if (IS_ERR(exp2)) { 105 if (IS_ERR(exp2)) {
@@ -167,16 +173,26 @@ static int nfsd_lookup_parent(struct svc_rqst *rqstp, struct dentry *dparent, st
167/* 173/*
168 * For nfsd purposes, we treat V4ROOT exports as though there was an 174 * For nfsd purposes, we treat V4ROOT exports as though there was an
169 * export at *every* directory. 175 * export at *every* directory.
176 * We return:
177 * '1' if this dentry *must* be an export point,
178 * '2' if it might be, if there is really a mount here, and
179 * '0' if there is no chance of an export point here.
170 */ 180 */
171int nfsd_mountpoint(struct dentry *dentry, struct svc_export *exp) 181int nfsd_mountpoint(struct dentry *dentry, struct svc_export *exp)
172{ 182{
173 if (d_mountpoint(dentry)) 183 if (!d_inode(dentry))
184 return 0;
185 if (exp->ex_flags & NFSEXP_V4ROOT)
174 return 1; 186 return 1;
175 if (nfsd4_is_junction(dentry)) 187 if (nfsd4_is_junction(dentry))
176 return 1; 188 return 1;
177 if (!(exp->ex_flags & NFSEXP_V4ROOT)) 189 if (d_mountpoint(dentry))
178 return 0; 190 /*
179 return d_inode(dentry) != NULL; 191 * Might only be a mountpoint in a different namespace,
192 * but we need to check.
193 */
194 return 2;
195 return 0;
180} 196}
181 197
182__be32 198__be32