]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - fs/nfs/dir.c
NFSv4: nfs_atomic_open() can race when looking up a non-regular file
[mirror_ubuntu-jammy-kernel.git] / fs / nfs / dir.c
index a78162238988ee46b158c4b962e29b7c93c5bbb7..fc75c16113436312cc14565f044ca2f6ebdd8eeb 100644 (file)
@@ -1987,12 +1987,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) {