* [PATCH] Revert "mm/slub: fix a memory leak in sysfs_slab_add()"
@ 2021-01-28 11:32 Wang Hai
2021-01-28 12:03 ` Vlastimil Babka
0 siblings, 1 reply; 2+ messages in thread
From: Wang Hai @ 2021-01-28 11:32 UTC (permalink / raw)
To: torvalds, cl, penberg, rientjes, iamjoonsoo.kim, akpm, vbabka
Cc: asmadeus, davem, ericvh, kuba, lucho, netdev, syzkaller-bugs,
v9fs-developer, linux-mm, linux-kernel,
syzbot+d0bd96b4696c1ef67991
This reverts commit dde3c6b72a16c2db826f54b2d49bdea26c3534a2.
syzbot report a double-free bug. The following case can cause this bug.
- mm/slab_common.c: create_cache(): if the __kmem_cache_create()
fails, it does:
out_free_cache:
kmem_cache_free(kmem_cache, s);
- but __kmem_cache_create() - at least for slub() - will have done
sysfs_slab_add(s)
-> sysfs_create_group() .. fails ..
-> kobject_del(&s->kobj); .. which frees s ...
We can't remove the kmem_cache_free() in create_cache(), because
other error cases of __kmem_cache_create() do not free this.
So, revert the commit dde3c6b72a16 ("mm/slub: fix a memory leak in
sysfs_slab_add()") to fix this.
Reported-by: syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com
Fixes: dde3c6b72a16 ("mm/slub: fix a memory leak in sysfs_slab_add()")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
mm/slub.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 69742ab9a21d..7ecbbbe5bc0c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5625,10 +5625,8 @@ 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) {
- kobject_put(&s->kobj);
+ if (err)
goto out;
- }
err = sysfs_create_group(&s->kobj, &slab_attr_group);
if (err)
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Revert "mm/slub: fix a memory leak in sysfs_slab_add()"
2021-01-28 11:32 [PATCH] Revert "mm/slub: fix a memory leak in sysfs_slab_add()" Wang Hai
@ 2021-01-28 12:03 ` Vlastimil Babka
0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2021-01-28 12:03 UTC (permalink / raw)
To: Wang Hai, torvalds, cl, penberg, rientjes, iamjoonsoo.kim, akpm
Cc: asmadeus, davem, ericvh, kuba, lucho, netdev, syzkaller-bugs,
v9fs-developer, linux-mm, linux-kernel,
syzbot+d0bd96b4696c1ef67991
On 1/28/21 12:32 PM, Wang Hai wrote:
> This reverts commit dde3c6b72a16c2db826f54b2d49bdea26c3534a2.
>
> syzbot report a double-free bug. The following case can cause this bug.
> - mm/slab_common.c: create_cache(): if the __kmem_cache_create()
> fails, it does:
>
> out_free_cache:
> kmem_cache_free(kmem_cache, s);
>
> - but __kmem_cache_create() - at least for slub() - will have done
>
> sysfs_slab_add(s)
> -> sysfs_create_group() .. fails ..
> -> kobject_del(&s->kobj); .. which frees s ...
>
> We can't remove the kmem_cache_free() in create_cache(), because
> other error cases of __kmem_cache_create() do not free this.
>
> So, revert the commit dde3c6b72a16 ("mm/slub: fix a memory leak in
> sysfs_slab_add()") to fix this.
>
> Reported-by: syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com
> Fixes: dde3c6b72a16 ("mm/slub: fix a memory leak in sysfs_slab_add()")
> Signed-off-by: Wang Hai <wanghai38@huawei.com>
Cc: <stable@vger.kernel.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Double-free is worse than a rare small memory leak. Which would still be nice to
fix, but I'm afraid it will be more complicated, so start with preventing the
worse issue, including stable.
> ---
> mm/slub.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 69742ab9a21d..7ecbbbe5bc0c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5625,10 +5625,8 @@ 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) {
> - kobject_put(&s->kobj);
> + if (err)
> goto out;
> - }
>
> err = sysfs_create_group(&s->kobj, &slab_attr_group);
> if (err)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-28 12:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 11:32 [PATCH] Revert "mm/slub: fix a memory leak in sysfs_slab_add()" Wang Hai
2021-01-28 12:03 ` Vlastimil Babka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).