linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Fix kobject memleak in SLUB
@ 2019-04-27 23:40 Tobin C. Harding
  2019-04-28  6:08 ` Pekka Enberg
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tobin C. Harding @ 2019-04-27 23:40 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Tobin C. Harding, Greg Kroah-Hartman, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, linux-mm,
	linux-kernel

Currently error return from kobject_init_and_add() is not followed by a
call to kobject_put().  This means there is a memory leak.

Add call to kobject_put() in error path of kobject_init_and_add().

Signed-off-by: Tobin C. Harding <tobin@kernel.org>
---
 mm/slub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index d30ede89f4a6..84a9d6c06c27 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5756,8 +5756,10 @@ static int sysfs_slab_add(struct kmem_cache *s)
 
 	s->kobj.kset = kset;
 	err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
-	if (err)
+	if (err) {
+		kobject_put(&s->kobj);
 		goto out;
+	}
 
 	err = sysfs_create_group(&s->kobj, &slab_attr_group);
 	if (err)
-- 
2.21.0


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

* Re: [PATCH] mm: Fix kobject memleak in SLUB
  2019-04-27 23:40 [PATCH] mm: Fix kobject memleak in SLUB Tobin C. Harding
@ 2019-04-28  6:08 ` Pekka Enberg
  2019-04-28 16:11 ` Greg Kroah-Hartman
  2019-04-30 22:54 ` Tobin C. Harding
  2 siblings, 0 replies; 4+ messages in thread
From: Pekka Enberg @ 2019-04-28  6:08 UTC (permalink / raw)
  To: Tobin C. Harding, Andrew Morton
  Cc: Greg Kroah-Hartman, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, linux-mm, linux-kernel



On 28/04/2019 2.40, Tobin C. Harding wrote:
> Currently error return from kobject_init_and_add() is not followed by a
> call to kobject_put().  This means there is a memory leak.
> 
> Add call to kobject_put() in error path of kobject_init_and_add().
> 
> Signed-off-by: Tobin C. Harding <tobin@kernel.org>

Reviewed-by: Pekka Enberg <penberg@kernel.org>


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

* Re: [PATCH] mm: Fix kobject memleak in SLUB
  2019-04-27 23:40 [PATCH] mm: Fix kobject memleak in SLUB Tobin C. Harding
  2019-04-28  6:08 ` Pekka Enberg
@ 2019-04-28 16:11 ` Greg Kroah-Hartman
  2019-04-30 22:54 ` Tobin C. Harding
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2019-04-28 16:11 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: Andrew Morton, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, linux-mm, linux-kernel

On Sun, Apr 28, 2019 at 09:40:00AM +1000, Tobin C. Harding wrote:
> Currently error return from kobject_init_and_add() is not followed by a
> call to kobject_put().  This means there is a memory leak.
> 
> Add call to kobject_put() in error path of kobject_init_and_add().
> 
> Signed-off-by: Tobin C. Harding <tobin@kernel.org>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


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

* Re: [PATCH] mm: Fix kobject memleak in SLUB
  2019-04-27 23:40 [PATCH] mm: Fix kobject memleak in SLUB Tobin C. Harding
  2019-04-28  6:08 ` Pekka Enberg
  2019-04-28 16:11 ` Greg Kroah-Hartman
@ 2019-04-30 22:54 ` Tobin C. Harding
  2 siblings, 0 replies; 4+ messages in thread
From: Tobin C. Harding @ 2019-04-30 22:54 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: Andrew Morton, Greg Kroah-Hartman, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, linux-mm,
	linux-kernel

On Sun, Apr 28, 2019 at 09:40:00AM +1000, Tobin C. Harding wrote:
> Currently error return from kobject_init_and_add() is not followed by a
> call to kobject_put().  This means there is a memory leak.
> 
> Add call to kobject_put() in error path of kobject_init_and_add().
> 
> Signed-off-by: Tobin C. Harding <tobin@kernel.org>
> ---
>  mm/slub.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index d30ede89f4a6..84a9d6c06c27 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5756,8 +5756,10 @@ static int sysfs_slab_add(struct kmem_cache *s)
>  
>  	s->kobj.kset = kset;
>  	err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
> -	if (err)
> +	if (err) {
> +		kobject_put(&s->kobj);
>  		goto out;
> +	}
>  
>  	err = sysfs_create_group(&s->kobj, &slab_attr_group);
>  	if (err)
> -- 
> 2.21.0
> 

This patch is not _completely_ correct.  Please do not consider for
merge.  There are a bunch of these on various LKML lists, once the
confusion has cleared I'll re-spin v2.

thanks,
Tobin.


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

end of thread, other threads:[~2019-04-30 22:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-27 23:40 [PATCH] mm: Fix kobject memleak in SLUB Tobin C. Harding
2019-04-28  6:08 ` Pekka Enberg
2019-04-28 16:11 ` Greg Kroah-Hartman
2019-04-30 22:54 ` Tobin C. Harding

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