linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slub: fix memory leak with using debugfs_lookup()
@ 2023-02-02 14:20 Greg Kroah-Hartman
  2023-02-03 14:27 ` Hyeonggon Yoo
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-02-02 14:20 UTC (permalink / raw)
  To: linux-mm
  Cc: Greg Kroah-Hartman, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Andrew Morton, Vlastimil Babka,
	Roman Gushchin, Hyeonggon Yoo, linux-kernel

When calling debugfs_lookup() the result must have dput() called on it,
otherwise the memory will leak over time.  To make things simpler, just
call debugfs_lookup_and_remove() instead which handles all of the logic
at once.

Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index 13459c69095a..4880e461fcc5 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -6449,7 +6449,7 @@ static void debugfs_slab_add(struct kmem_cache *s)
 
 void debugfs_slab_release(struct kmem_cache *s)
 {
-	debugfs_remove_recursive(debugfs_lookup(s->name, slab_debugfs_root));
+	debugfs_lookup_and_remove(s->name, slab_debugfs_root);
 }
 
 static int __init slab_debugfs_init(void)
-- 
2.39.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slub: fix memory leak with using debugfs_lookup()
  2023-02-02 14:20 [PATCH] mm/slub: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
@ 2023-02-03 14:27 ` Hyeonggon Yoo
  2023-02-03 17:47 ` Roman Gushchin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Hyeonggon Yoo @ 2023-02-03 14:27 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-mm, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Andrew Morton, Vlastimil Babka, Roman Gushchin,
	linux-kernel

On Thu, Feb 02, 2023 at 03:20:22PM +0100, Greg Kroah-Hartman wrote:
> When calling debugfs_lookup() the result must have dput() called on it,
> otherwise the memory will leak over time.  To make things simpler, just
> call debugfs_lookup_and_remove() instead which handles all of the logic
> at once.
> 
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  mm/slub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 13459c69095a..4880e461fcc5 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -6449,7 +6449,7 @@ static void debugfs_slab_add(struct kmem_cache *s)
>  
>  void debugfs_slab_release(struct kmem_cache *s)
>  {
> -	debugfs_remove_recursive(debugfs_lookup(s->name, slab_debugfs_root));
> +	debugfs_lookup_and_remove(s->name, slab_debugfs_root);
>  }

Looks good to me.
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>

Thank you for fixing this.

>  static int __init slab_debugfs_init(void)
> -- 
> 2.39.1
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slub: fix memory leak with using debugfs_lookup()
  2023-02-02 14:20 [PATCH] mm/slub: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
  2023-02-03 14:27 ` Hyeonggon Yoo
@ 2023-02-03 17:47 ` Roman Gushchin
  2023-02-05 22:27 ` David Rientjes
  2023-02-06 15:36 ` Vlastimil Babka
  3 siblings, 0 replies; 5+ messages in thread
From: Roman Gushchin @ 2023-02-03 17:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-mm, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Andrew Morton, Vlastimil Babka, Hyeonggon Yoo,
	linux-kernel

On Thu, Feb 02, 2023 at 03:20:22PM +0100, Greg Kroah-Hartman wrote:
> When calling debugfs_lookup() the result must have dput() called on it,
> otherwise the memory will leak over time.  To make things simpler, just
> call debugfs_lookup_and_remove() instead which handles all of the logic
> at once.
> 
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Good catch!

Acked-by: Roman Gushchin <roman.gushchin@linux.dev>

Thanks!


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slub: fix memory leak with using debugfs_lookup()
  2023-02-02 14:20 [PATCH] mm/slub: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
  2023-02-03 14:27 ` Hyeonggon Yoo
  2023-02-03 17:47 ` Roman Gushchin
@ 2023-02-05 22:27 ` David Rientjes
  2023-02-06 15:36 ` Vlastimil Babka
  3 siblings, 0 replies; 5+ messages in thread
From: David Rientjes @ 2023-02-05 22:27 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-mm, Christoph Lameter, Pekka Enberg, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Roman Gushchin, Hyeonggon Yoo,
	linux-kernel

On Thu, 2 Feb 2023, Greg Kroah-Hartman wrote:

> When calling debugfs_lookup() the result must have dput() called on it,
> otherwise the memory will leak over time.  To make things simpler, just
> call debugfs_lookup_and_remove() instead which handles all of the logic
> at once.
> 
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: David Rientjes <rientjes@google.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slub: fix memory leak with using debugfs_lookup()
  2023-02-02 14:20 [PATCH] mm/slub: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
                   ` (2 preceding siblings ...)
  2023-02-05 22:27 ` David Rientjes
@ 2023-02-06 15:36 ` Vlastimil Babka
  3 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka @ 2023-02-06 15:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-mm
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Roman Gushchin, Hyeonggon Yoo, linux-kernel

On 2/2/23 15:20, Greg Kroah-Hartman wrote:
> When calling debugfs_lookup() the result must have dput() called on it,
> otherwise the memory will leak over time.  To make things simpler, just
> call debugfs_lookup_and_remove() instead which handles all of the logic
> at once.
> 
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Thanks, added to slab/for-6.3/fixes

> ---
>  mm/slub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 13459c69095a..4880e461fcc5 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -6449,7 +6449,7 @@ static void debugfs_slab_add(struct kmem_cache *s)
>  
>  void debugfs_slab_release(struct kmem_cache *s)
>  {
> -	debugfs_remove_recursive(debugfs_lookup(s->name, slab_debugfs_root));
> +	debugfs_lookup_and_remove(s->name, slab_debugfs_root);
>  }
>  
>  static int __init slab_debugfs_init(void)



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-06 15:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 14:20 [PATCH] mm/slub: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
2023-02-03 14:27 ` Hyeonggon Yoo
2023-02-03 17:47 ` Roman Gushchin
2023-02-05 22:27 ` David Rientjes
2023-02-06 15:36 ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox