]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFSv4: nfs_atomic_open() can race when looking up a non-regular file
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 6 Jan 2022 23:24:03 +0000 (18:24 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Feb 2022 17:23:09 +0000 (18:23 +0100)
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>
fs/nfs/dir.c

index f8d805c8046403acb50cfb7ca45b72ab66b259d4..f2ea5c244531384fd39ed054b1be80b31b3bbf36 100644 (file)
@@ -1631,12 +1631,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) {