Skip to content

Commit 80da026

Browse files
koct9itorvalds
authored andcommitted
mm/slub: fix slab double-free in case of duplicate sysfs filename
sysfs_slab_add() shouldn't call kobject_put at error path: this puts last reference of kmem-cache kobject and frees it. Kmem cache will be freed second time at error path in kmem_cache_create(). For example this happens when slub debug was enabled in runtime and somebody creates new kmem cache: # echo 1 | tee /sys/kernel/slab/*/sanity_checks # modprobe configfs "configfs_dir_cache" cannot be merged because existing slab have debug and cannot create new slab because unique name ":t-0000096" already taken. Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Acked-by: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Acked-by: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 588f8ba commit 80da026

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

mm/slub.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5283,7 +5283,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
52835283
s->kobj.kset = cache_kset(s);
52845284
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
52855285
if (err)
5286-
goto out_put_kobj;
5286+
goto out;
52875287

52885288
err = sysfs_create_group(&s->kobj, &slab_attr_group);
52895289
if (err)
@@ -5310,8 +5310,6 @@ static int sysfs_slab_add(struct kmem_cache *s)
53105310
return err;
53115311
out_del_kobj:
53125312
kobject_del(&s->kobj);
5313-
out_put_kobj:
5314-
kobject_put(&s->kobj);
53155313
goto out;
53165314
}
53175315

0 commit comments

Comments
 (0)