Re: [PATCH] sched,debug: fix dentry leak in update_sched_domain_debugfs

From: Peter Zijlstra
Date: Mon Jul 11 2022 - 04:04:18 EST


On Mon, Jul 11, 2022 at 11:03:41AM +0800, Major Chen wrote:
>  
> update_sched_domain_debugfs() uses debugfs_lookup() to find wanted dentry(which has
> been created by debugfs_create_dir() before), but not call dput() to return this dentry
> back. This result in dentry leak even debugfs_remove() is called.
>  
> Signed-off-by: major.chen <major.chen@xxxxxxxxxxx>
> ---
>  kernel/sched/debug.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>  
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index bb3d63b..4ffea2d 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -412,11 +412,14 @@ void update_sched_domain_debugfs(void)
>  
>          for_each_cpu(cpu, sd_sysctl_cpus) {
>                  struct sched_domain *sd;
> -                struct dentry *d_cpu;
> +                struct dentry *d_cpu, *d_lookup;
>                  char buf[32];
>  
>                  snprintf(buf, sizeof(buf), "cpu%d", cpu);
> -                debugfs_remove(debugfs_lookup(buf, sd_dentry));
> +                d_lookup = debugfs_lookup(buf, sd_dentry);
> +                debugfs_remove(d_lookup);
> +                if (!IS_ERR_OR_NULL(d_lookup))
> +                        dput(d_lookup);
>                  d_cpu = debugfs_create_dir(buf, sd_dentry);
>  
>                  i = 0;

Please try again, while not HTML, this email is severely whitespace
mangled (there's no '\t' characters in it for one).