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

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Fri Feb 25 11:17:44 MSK 2022


Reviewed-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>

On 24.02.2022 21:07, Konstantin Khorenko wrote:
> 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);

-- 
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.


More information about the Devel mailing list