Wang Hai
53bb2a6566
mm/slub: fix a memory leak in sysfs_slab_add()
commit dde3c6b72a upstream.
syzkaller reports for memory leak when kobject_init_and_add() returns an
error in the function sysfs_slab_add() [1]
When this happened, the function kobject_put() is not called for the
corresponding kobject, which potentially leads to memory leak.
This patch fixes the issue by calling kobject_put() even if
kobject_init_and_add() fails.
[1]
BUG: memory leak
unreferenced object 0xffff8880a6d4be88 (size 8):
comm "syz-executor.3", pid 946, jiffies 4295772514 (age 18.396s)
hex dump (first 8 bytes):
70 69 64 5f 33 00 ff ff pid_3...
backtrace:
kstrdup+0x35/0x70 mm/util.c:60
kstrdup_const+0x3d/0x50 mm/util.c:82
kvasprintf_const+0x112/0x170 lib/kasprintf.c:48
kobject_set_name_vargs+0x55/0x130 lib/kobject.c:289
kobject_add_varg lib/kobject.c:384 [inline]
kobject_init_and_add+0xd8/0x170 lib/kobject.c:473
sysfs_slab_add+0x1d8/0x290 mm/slub.c:5811
__kmem_cache_create+0x50a/0x570 mm/slub.c:4384
create_cache+0x113/0x1e0 mm/slab_common.c:407
kmem_cache_create_usercopy+0x1a1/0x260 mm/slab_common.c:505
kmem_cache_create+0xd/0x10 mm/slab_common.c:564
create_pid_cachep kernel/pid_namespace.c:54 [inline]
create_pid_namespace kernel/pid_namespace.c:96 [inline]
copy_pid_ns+0x77c/0x8f0 kernel/pid_namespace.c:148
create_new_namespaces+0x26b/0xa30 kernel/nsproxy.c:95
unshare_nsproxy_namespaces+0xa7/0x1e0 kernel/nsproxy.c:229
ksys_unshare+0x3d2/0x770 kernel/fork.c:2969
__do_sys_unshare kernel/fork.c:3037 [inline]
__se_sys_unshare kernel/fork.c:3035 [inline]
__x64_sys_unshare+0x2d/0x40 kernel/fork.c:3035
do_syscall_64+0xa1/0x530 arch/x86/entry/common.c:295
Fixes: 80da026a8e ("mm/slub: fix slab double-free in case of duplicate sysfs filename")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Link: http://lkml.kernel.org/r/20200602115033.1054-1-wanghai38@huawei.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-06-22 09:05:08 +02:00
..
2019-03-05 17:58:50 +01:00
2019-06-15 11:54:01 +02:00
2019-08-06 19:06:51 +02:00
2019-10-05 13:10:13 +02:00
2019-11-12 19:21:20 +01:00
2019-12-01 09:17:07 +01:00
2019-07-31 07:27:08 +02:00
2020-01-29 16:43:27 +01:00
2020-03-11 14:15:00 +01:00
2019-11-20 18:45:20 +01:00
2020-04-29 16:31:27 +02:00
2019-12-05 09:20:57 +01:00
2019-06-15 11:54:00 +02:00
2019-06-22 08:15:21 +02:00
2019-08-25 10:47:58 +02:00
2020-04-29 16:31:28 +02:00
2019-06-19 08:17:59 +02:00
2019-12-05 09:20:58 +01:00
2020-03-25 08:06:12 +01:00
2019-11-20 18:47:53 +01:00
2020-02-11 04:33:56 -08:00
2019-10-29 09:19:59 +01:00
2019-12-17 20:35:45 +01:00
2020-04-13 10:45:06 +02:00
2020-02-11 04:33:56 -08:00
2019-05-22 07:37:40 +02:00
2019-07-10 09:53:40 +02:00
2020-01-09 10:19:03 +01:00
2019-07-31 07:27:08 +02:00
2020-03-11 14:15:00 +01:00
2020-06-07 13:17:53 +02:00
2020-03-25 08:06:13 +01:00
2019-10-05 13:10:07 +02:00
2020-05-14 07:57:21 +02:00
2019-04-05 22:32:58 +02:00
2019-07-03 13:14:45 +02:00
2019-12-01 09:17:35 +01:00
2019-10-29 09:19:58 +01:00
2019-04-05 22:32:59 +02:00
2018-11-13 11:08:46 -08:00
2020-01-23 08:21:31 +01:00
2019-02-12 19:47:12 +01:00
2019-06-15 11:54:11 +02:00
2019-08-25 10:47:43 +02:00
2020-05-20 08:18:32 +02:00
2020-01-23 08:21:30 +01:00
2019-06-15 11:54:01 +02:00
2019-04-03 06:26:28 +02:00
2020-06-22 09:05:08 +02:00
2020-01-29 16:43:26 +01:00
2019-07-31 07:27:03 +02:00
2019-04-05 22:32:58 +02:00
2018-12-05 19:32:13 +01:00
2019-10-11 18:20:58 +02:00
2019-05-22 07:37:40 +02:00
2020-06-22 09:05:01 +02:00
2020-06-03 08:19:49 +02:00
2019-10-17 13:45:19 -07:00
2020-02-28 16:38:50 +01:00
2019-12-13 08:51:27 +01:00
2018-12-01 09:37:33 +01:00
2020-01-09 10:19:00 +01:00