Skip to content

Commit

Permalink
mm/slub: fix memory leak in sysfs_slab_add
Browse files Browse the repository at this point in the history
When `kobject_init_and_add` returns an error, `kobject_put`
must be called to properly clean up the memory associated
with the object.

Otherwise, kmemleak will report memory leak when
`kobject_init_and_add` fails:

unreferenced object 0xffff8881022795c0 (size 16):
  comm "insmod", pid 8408, jiffies 4294975975 (age 109.788s)
  hex dump (first 16 bytes):
    64 6c 6d 5f 77 72 69 74 65 71 75 65 75 65 00 ff  dlm_writequeue..
  backtrace:
    [<000000009ca6570f>] __kmalloc_node_track_caller+0x42/0x1b0
    [<00000000355bf37e>] kstrdup+0x3b/0x70
    [<000000005a5c80f0>] kstrdup_const+0x35/0x60
    [<000000000a9534ea>] kvasprintf_const+0xf5/0x180
    [<000000006922da10>] kobject_set_name_vargs+0x56/0x150
    [<0000000086379d67>] kobject_init_and_add+0xc9/0x160
    [<0000000019019cf9>] sysfs_slab_add+0x17c/0x220
    [<0000000040367fb8>] __kmem_cache_create+0x484/0x520
    [<00000000a0979fa9>] kmem_cache_create_usercopy+0x1fc/0x2e0
    [<00000000b8f8fa26>] kmem_cache_create+0xd/0x20
    [<00000000405456b4>] 0xffffffffc00a01cc
    [<000000003bc59b30>] 0xffffffffc00a011f
    [<00000000e0ca5d28>] do_one_initcall+0xcd/0x4d0
    [<00000000b03f82d8>] do_init_module+0x1c7/0x610
    [<0000000027749c9e>] load_module+0x5881/0x6bf0
    [<00000000b4013973>] __do_sys_finit_module+0x135/0x1d0

Fixes: 26e4f20 ("slub: Fix possible format string bug")
Signed-off-by: Zeng Heng <[email protected]>
  • Loading branch information
henryZe committed Dec 7, 2022
1 parent 8ed710d commit 64bd1a8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -5961,6 +5961,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
sysfs_slab_alias(s, s->name);
}
out:
kobject_put(&s->kobj);
if (!unmergeable)
kfree(name);
return err;
Expand Down

0 comments on commit 64bd1a8

Please sign in to comment.