Skip to content

Commit ac79516

Browse files
Trond Myklebustamschuma-ntap
Trond Myklebust
authored andcommitted
NFSv4: Handle case where the lookup of a directory fails
If the application sets the O_DIRECTORY flag, and tries to open a regular file, nfs_atomic_open() will punt to doing a regular lookup. If the server then returns a regular file, we will happily return a file descriptor with uninitialised open state. The fix is to return the expected ENOTDIR error in these cases. Reported-by: Lyu Tao <tao.lyu@epfl.ch> Fixes: 0dd2b47 ("nfs: implement i_op->atomic_open()") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 34bf20c commit ac79516

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: fs/nfs/dir.c

+13
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,19 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
19941994

19951995
no_open:
19961996
res = nfs_lookup(dir, dentry, lookup_flags);
1997+
if (!res) {
1998+
inode = d_inode(dentry);
1999+
if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
2000+
!S_ISDIR(inode->i_mode))
2001+
res = ERR_PTR(-ENOTDIR);
2002+
} else if (!IS_ERR(res)) {
2003+
inode = d_inode(res);
2004+
if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
2005+
!S_ISDIR(inode->i_mode)) {
2006+
dput(res);
2007+
res = ERR_PTR(-ENOTDIR);
2008+
}
2009+
}
19972010
if (switched) {
19982011
d_lookup_done(dentry);
19992012
if (!res)

0 commit comments

Comments
 (0)