summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@hammerspace.com>2022-01-06 18:24:03 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-02-08 18:15:27 +0100
commite3fef0d7eeb2339e0b1c324da6cea4dd0128ac1d (patch)
treef615c06a5d1601010a3f5795044f14cb06a917bf
parent8788981e120694a82a3672e062fe4ea99446634a (diff)
downloadlinux-stable-e3fef0d7eeb2339e0b1c324da6cea4dd0128ac1d.tar.gz
linux-stable-e3fef0d7eeb2339e0b1c324da6cea4dd0128ac1d.tar.bz2
linux-stable-e3fef0d7eeb2339e0b1c324da6cea4dd0128ac1d.zip
NFSv4: nfs_atomic_open() can race when looking up a non-regular file
commit 1751fc1db36f6f411709e143d5393f92d12137a9 upstream. If the file type changes back to being a regular file on the server between the failed OPEN and our LOOKUP, then we need to re-run the OPEN. Fixes: 0dd2b474d0b6 ("nfs: implement i_op->atomic_open()") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/nfs/dir.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index e7986bc90ea8..24e854dfb3c2 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1607,12 +1607,17 @@ no_open:
if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
!S_ISDIR(inode->i_mode))
res = ERR_PTR(-ENOTDIR);
+ else if (inode && S_ISREG(inode->i_mode))
+ res = ERR_PTR(-EOPENSTALE);
} else if (!IS_ERR(res)) {
inode = d_inode(res);
if ((lookup_flags & LOOKUP_DIRECTORY) && inode &&
!S_ISDIR(inode->i_mode)) {
dput(res);
res = ERR_PTR(-ENOTDIR);
+ } else if (inode && S_ISREG(inode->i_mode)) {
+ dput(res);
+ res = ERR_PTR(-EOPENSTALE);
}
}
if (switched) {