[Devel] [PATCH rh9] ve/kernfs: handle negative dcache entries in kernfs_iop_lookup()

Konstantin Khorenko khorenko at virtuozzo.com
Thu Feb 24 21:07:25 MSK 2022


After ms comit c7e7c04274b1 ("kernfs: use VFS negative dentry caching")
kernfs_iop_lookup() is intended to handle negative dcache entries,
thus kernfs_find_ns() might return NULL and kernfs_d_visible() crashes.

Make sure kernfs_d_visible() is called with non-zero kn.

Fixes: 62c36c3dbf08 ("ve/kernfs: hide forbidden entries in container")
https://jira.sw.ru/browse/PSBM-138339

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 fs/kernfs/dir.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index efd6ec30e287..26c0849c609f 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -1118,11 +1118,6 @@ static struct dentry *kernfs_iop_lookup(struct inode *dir,
 
 	kn = kernfs_find_ns(parent, dentry->d_name.name, ns);
 
-	if(!kernfs_d_visible(kn, kernfs_info(dentry->d_sb))) {
-		up_read(&kernfs_rwsem);
-		return NULL;
-	}
-
 	/* attach dentry and inode */
 	if (kn) {
 		/* Inactive nodes are invisible to the VFS so don't
@@ -1132,6 +1127,12 @@ static struct dentry *kernfs_iop_lookup(struct inode *dir,
 			up_read(&kernfs_rwsem);
 			return NULL;
 		}
+
+		if (!kernfs_d_visible(kn, kernfs_info(dentry->d_sb))) {
+			up_read(&kernfs_rwsem);
+			return NULL;
+		}
+
 		inode = kernfs_get_inode(dir->i_sb, kn);
 		if (!inode)
 			inode = ERR_PTR(-ENOMEM);
-- 
2.31.1



More information about the Devel mailing list