* slub: fix leak of 'name' in sysfs_slab_add @ 2014-03-06 21:11 Dave Jones 2014-03-07 6:18 ` Vladimir Davydov 0 siblings, 1 reply; 4+ messages in thread From: Dave Jones @ 2014-03-06 21:11 UTC (permalink / raw) To: Linux Kernel; +Cc: linux-mm, cl, penberg The failure paths of sysfs_slab_add don't release the allocation of 'name' made by create_unique_id() a few lines above the context of the diff below. Create a common exit path to make it more obvious what needs freeing. Signed-off-by: Dave Jones <davej@fedoraproject.org> diff --git a/mm/slub.c b/mm/slub.c index 25f14ad8f817..b2181d2682ac 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5197,17 +5197,13 @@ static int sysfs_slab_add(struct kmem_cache *s) s->kobj.kset = slab_kset; err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name); - if (err) { - kobject_put(&s->kobj); - return err; - } + if (err) + goto err_out; err = sysfs_create_group(&s->kobj, &slab_attr_group); - if (err) { - kobject_del(&s->kobj); - kobject_put(&s->kobj); - return err; - } + if (err) + goto err_sysfs; + kobject_uevent(&s->kobj, KOBJ_ADD); if (!unmergeable) { /* Setup first alias */ @@ -5215,6 +5211,13 @@ static int sysfs_slab_add(struct kmem_cache *s) kfree(name); } return 0; + +err_sysfs: + kobject_del(&s->kobj); +err_out: + kobject_put(&s->kobj); + kfree(name); + return err; } static void sysfs_slab_remove(struct kmem_cache *s) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: slub: fix leak of 'name' in sysfs_slab_add 2014-03-06 21:11 slub: fix leak of 'name' in sysfs_slab_add Dave Jones @ 2014-03-07 6:18 ` Vladimir Davydov 2014-03-07 15:32 ` Dave Jones 0 siblings, 1 reply; 4+ messages in thread From: Vladimir Davydov @ 2014-03-07 6:18 UTC (permalink / raw) To: Dave Jones; +Cc: Linux Kernel, linux-mm, cl, penberg, Andrew Morton [adding Andrew to Cc] On 03/07/2014 01:11 AM, Dave Jones wrote: > The failure paths of sysfs_slab_add don't release the allocation of 'name' > made by create_unique_id() a few lines above the context of the diff below. > Create a common exit path to make it more obvious what needs freeing. > > Signed-off-by: Dave Jones <davej@fedoraproject.org> > > diff --git a/mm/slub.c b/mm/slub.c > index 25f14ad8f817..b2181d2682ac 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -5197,17 +5197,13 @@ static int sysfs_slab_add(struct kmem_cache *s) > > s->kobj.kset = slab_kset; > err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name); > - if (err) { > - kobject_put(&s->kobj); > - return err; > - } > + if (err) > + goto err_out; > > err = sysfs_create_group(&s->kobj, &slab_attr_group); > - if (err) { > - kobject_del(&s->kobj); > - kobject_put(&s->kobj); > - return err; > - } > + if (err) > + goto err_sysfs; > + > kobject_uevent(&s->kobj, KOBJ_ADD); > if (!unmergeable) { > /* Setup first alias */ > @@ -5215,6 +5211,13 @@ static int sysfs_slab_add(struct kmem_cache *s) > kfree(name); > } > return 0; > + > +err_sysfs: > + kobject_del(&s->kobj); > +err_out: > + kobject_put(&s->kobj); > + kfree(name); > + return err; > } We should free the name only if !unmergeable, because: sysfs_slab_add(): if (unmergeable) { /* * Slabcache can never be merged so we can use the name proper. * This is typically the case for debug situations. In that * case we can catch duplicate names easily. */ sysfs_remove_link(&slab_kset->kobj, s->name); name = s->name; } else { /* * Create a unique name for the slab as a target * for the symlinks. */ name = create_unique_id(s); } Since this function was modified in the mmotm tree, I would propose something like this on top of mmotm to avoid further merge conflicts: diff --git a/mm/slub.c b/mm/slub.c index c6eb29d65847..f4ca525c05b0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5214,25 +5214,19 @@ static int sysfs_slab_add(struct kmem_cache *s) s->kobj.kset = cache_kset(s); err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name); - if (err) { - kobject_put(&s->kobj); - return err; - } + if (err) + goto out_put_kobj; err = sysfs_create_group(&s->kobj, &slab_attr_group); - if (err) { - kobject_del(&s->kobj); - kobject_put(&s->kobj); - return err; - } + if (err) + goto out_del_kobj; #ifdef CONFIG_MEMCG_KMEM if (is_root_cache(s)) { s->memcg_kset = kset_create_and_add("cgroup", NULL, &s->kobj); if (!s->memcg_kset) { - kobject_del(&s->kobj); - kobject_put(&s->kobj); - return -ENOMEM; + err = -ENOMEM; + goto out_del_kobj; } } #endif @@ -5241,9 +5235,16 @@ static int sysfs_slab_add(struct kmem_cache *s) if (!unmergeable) { /* Setup first alias */ sysfs_slab_alias(s, s->name); - kfree(name); } - return 0; +out: + if (!unmergeable) + kfree(name); + return err; +out_del_kobj: + kobject_del(&s->kobj); +out_put_kobj: + kobject_put(&s->kobj); + goto out; } static void sysfs_slab_remove(struct kmem_cache *s) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: slub: fix leak of 'name' in sysfs_slab_add 2014-03-07 6:18 ` Vladimir Davydov @ 2014-03-07 15:32 ` Dave Jones 2014-03-07 17:14 ` Christoph Lameter 0 siblings, 1 reply; 4+ messages in thread From: Dave Jones @ 2014-03-07 15:32 UTC (permalink / raw) To: Vladimir Davydov; +Cc: Linux Kernel, linux-mm, cl, penberg, Andrew Morton On Fri, Mar 07, 2014 at 10:18:04AM +0400, Vladimir Davydov wrote: > [adding Andrew to Cc] > > On 03/07/2014 01:11 AM, Dave Jones wrote: > > The failure paths of sysfs_slab_add don't release the allocation of 'name' > > made by create_unique_id() a few lines above the context of the diff below. > > Create a common exit path to make it more obvious what needs freeing. > > > > Signed-off-by: Dave Jones <davej@fedoraproject.org> > > > > Since this function was modified in the mmotm tree, I would propose > something like this on top of mmotm to avoid further merge conflicts: Looks good to me. thanks, Dave -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: slub: fix leak of 'name' in sysfs_slab_add 2014-03-07 15:32 ` Dave Jones @ 2014-03-07 17:14 ` Christoph Lameter 0 siblings, 0 replies; 4+ messages in thread From: Christoph Lameter @ 2014-03-07 17:14 UTC (permalink / raw) To: Dave Jones Cc: Vladimir Davydov, Linux Kernel, linux-mm, penberg, Andrew Morton On Fri, 7 Mar 2014, Dave Jones wrote: > > Since this function was modified in the mmotm tree, I would propose > > something like this on top of mmotm to avoid further merge conflicts: > > Looks good to me. Acked-by: Christoph Lameter <cl@linux.com> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a> ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-07 17:14 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-03-06 21:11 slub: fix leak of 'name' in sysfs_slab_add Dave Jones 2014-03-07 6:18 ` Vladimir Davydov 2014-03-07 15:32 ` Dave Jones 2014-03-07 17:14 ` Christoph Lameter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox