Skip to content

Commit ac865cd

Browse files
Trond MyklebustJohn Donnelly
authored andcommitted
NFSv4: Handle case where the lookup of a directory fails
commit ac79516 upstream. 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 <[email protected]> Fixes: 0dd2b47 ("nfs: implement i_op->atomic_open()") Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Anna Schumaker <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 516f348b759f6a92819820a3f56d678458e22cc8) Orabug: 33958155 CVE: CVE-2022-24448 Signed-off-by: Sherry Yang <[email protected]> Signed-off-by: John Donnelly <[email protected]>
1 parent c014ec1 commit ac865cd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs/nfs/dir.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,19 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
16121612

16131613
no_open:
16141614
res = nfs_lookup(dir, dentry, lookup_flags);
1615+
if (!res) {
1616+
inode = d_inode(dentry);
1617+
if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
1618+
!S_ISDIR(inode->i_mode))
1619+
res = ERR_PTR(-ENOTDIR);
1620+
} else if (!IS_ERR(res)) {
1621+
inode = d_inode(res);
1622+
if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
1623+
!S_ISDIR(inode->i_mode)) {
1624+
dput(res);
1625+
res = ERR_PTR(-ENOTDIR);
1626+
}
1627+
}
16151628
if (switched) {
16161629
d_lookup_done(dentry);
16171630
if (!res)

0 commit comments

Comments
 (0)