Skip to content

Commit a3fbbde

Browse files
Al Virotorvalds
authored andcommitted
VFS: we need to set LOOKUP_JUMPED on mountpoint crossing
Mountpoint crossing is similar to following procfs symlinks - we do not get ->d_revalidate() called for dentry we have arrived at, with unpleasant consequences for NFS4. Simple way to reproduce the problem in mainline: cat >/tmp/a.c <<'EOF' #include <unistd.h> #include <fcntl.h> #include <stdio.h> main() { struct flock fl = {.l_type = F_RDLCK, .l_whence = SEEK_SET, .l_len = 1}; if (fcntl(0, F_SETLK, &fl)) perror("setlk"); } EOF cc /tmp/a.c -o /tmp/test then on nfs4: mount --bind file1 file2 /tmp/test < file1 # ok /tmp/test < file2 # spews "setlk: No locks available"... What happens is the missing call of ->d_revalidate() after mountpoint crossing and that's where NFS4 would issue OPEN request to server. The fix is simple - treat mountpoint crossing the same way we deal with following procfs-style symlinks. I.e. set LOOKUP_JUMPED... Cc: [email protected] Signed-off-by: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 54a0f91 commit a3fbbde

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fs/namei.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ static int follow_managed(struct path *path, unsigned flags)
852852
mntput(path->mnt);
853853
if (ret == -EISDIR)
854854
ret = 0;
855-
return ret;
855+
return ret < 0 ? ret : need_mntput;
856856
}
857857

858858
int follow_down_one(struct path *path)
@@ -900,6 +900,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
900900
break;
901901
path->mnt = mounted;
902902
path->dentry = mounted->mnt_root;
903+
nd->flags |= LOOKUP_JUMPED;
903904
nd->seq = read_seqcount_begin(&path->dentry->d_seq);
904905
/*
905906
* Update the inode too. We don't need to re-check the
@@ -1213,6 +1214,8 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
12131214
path_put_conditional(path, nd);
12141215
return err;
12151216
}
1217+
if (err)
1218+
nd->flags |= LOOKUP_JUMPED;
12161219
*inode = path->dentry->d_inode;
12171220
return 0;
12181221
}
@@ -2146,6 +2149,10 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
21462149
}
21472150

21482151
/* create side of things */
2152+
/*
2153+
* This will *only* deal with leaving RCU mode - LOOKUP_JUMPED has been
2154+
* cleared when we got to the last component we are about to look up
2155+
*/
21492156
error = complete_walk(nd);
21502157
if (error)
21512158
return ERR_PTR(error);
@@ -2214,6 +2221,9 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
22142221
if (error < 0)
22152222
goto exit_dput;
22162223

2224+
if (error)
2225+
nd->flags |= LOOKUP_JUMPED;
2226+
22172227
error = -ENOENT;
22182228
if (!path->dentry->d_inode)
22192229
goto exit_dput;
@@ -2223,6 +2233,10 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
22232233

22242234
path_to_nameidata(path, nd);
22252235
nd->inode = path->dentry->d_inode;
2236+
/* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
2237+
error = complete_walk(nd);
2238+
if (error)
2239+
goto exit;
22262240
error = -EISDIR;
22272241
if (S_ISDIR(nd->inode->i_mode))
22282242
goto exit;

0 commit comments

Comments
 (0)