FAILED: patch "[PATCH] NFSv4: Handle case where the lookup of a directory fails" failed to apply to 4.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ac795161c93699d600db16c1a8cc23a65a1eceaf Mon Sep 17 00:00:00 2001
From: Trond Myklebust <[email protected]>
Date: Thu, 6 Jan 2022 18:24:02 -0500
Subject: [PATCH] NFSv4: Handle case where the lookup of a directory fails
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.
fs/nfs/dir.c +13 -0
@@ -1994,6 +1994,19 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, no_open: res =nfs_lookup (dir, dentry, lookup_flags); +if (!res) { + inode =d_inode (dentry); +if ((lookup_flags &LOOKUP_DIRECTORY ) && inode && + !S_ISDIR (inode->i_mode)) + res =ERR_PTR (-ENOTDIR ); + }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 ); + } + }if (switched) {d_lookup_done (dentry);if (!res)