Skip to content

Commit

Permalink
Revert "mm/slub: fix a memory leak in sysfs_slab_add()"
Browse files Browse the repository at this point in the history
commit 757fed1 upstream.

This reverts commit dde3c6b.

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 dde3c6b ("mm/slub: fix a memory leak in
sysfs_slab_add()") to fix this.

Reported-by: syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com
Fixes: dde3c6b ("mm/slub: fix a memory leak in sysfs_slab_add()")
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Wang Hai authored and Greg Kroah-Hartman committed Jan 30, 2021
1 parent b5fb0ad commit ab98f2e
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -5425,10 +5425,8 @@ 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);
if (err)
goto out;
}

err = sysfs_create_group(&s->kobj, &slab_attr_group);
if (err)
Expand Down

0 comments on commit ab98f2e

Please sign in to comment.