From: Trond Myklebust Date: Thu, 6 Jan 2022 23:24:03 +0000 (-0500) Subject: NFSv4: nfs_atomic_open() can race when looking up a non-regular file X-Git-Tag: v5.4.176~25 X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=4fd45ff2b40487d36e5150f28666b1f7bf85161f;p=wrapfs-3.14.y.git 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 Signed-off-by: Anna Schumaker Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 492f506281e5..43c5223294e3 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1643,12 +1643,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) {