Commit 65f1a0d3 authored by Wang Hai's avatar Wang Hai Committed by Ulf Hansson

memstick: Fix error cleanup path of memstick_init

If bus_register fails. On its error handling path, it has cleaned up
what it has done. There is no need to call bus_unregister again.
Otherwise, if bus_unregister is called, issues such as null-ptr-deref
will arise.

Syzkaller report this:

kobject_add_internal failed for memstick (error: -12 parent: bus)
BUG: KASAN: null-ptr-deref in sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467
Read of size 8 at addr 0000000000000078 by task syz-executor.0/4460

Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0xa9/0x10e lib/dump_stack.c:113
 __kasan_report+0x171/0x18d mm/kasan/report.c:321
 kasan_report+0xe/0x20 mm/kasan/common.c:614
 sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467
 sysfs_remove_file include/linux/sysfs.h:519 [inline]
 bus_remove_file+0x6c/0x90 drivers/base/bus.c:145
 remove_probe_files drivers/base/bus.c:599 [inline]
 bus_unregister+0x6e/0x100 drivers/base/bus.c:916 ? 0xffffffffc1590000
 memstick_init+0x7a/0x1000 [memstick]
 do_one_initcall+0xb9/0x3b5 init/main.c:914
 do_init_module+0xe0/0x330 kernel/module.c:3468
 load_module+0x38eb/0x4270 kernel/module.c:3819
 __do_sys_finit_module+0x162/0x190 kernel/module.c:3909
 do_syscall_64+0x72/0x2a0 arch/x86/entry/common.c:298
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Fixes: baf8532a ("memstick: initial commit for Sony MemoryStick support")
Reported-by: default avatarHulk Robot <hulkci@huawei.com>
Signed-off-by: default avatarWang Hai <wanghai26@huawei.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent acdc8e71
...@@ -629,13 +629,18 @@ static int __init memstick_init(void) ...@@ -629,13 +629,18 @@ static int __init memstick_init(void)
return -ENOMEM; return -ENOMEM;
rc = bus_register(&memstick_bus_type); rc = bus_register(&memstick_bus_type);
if (!rc) if (rc)
goto error_destroy_workqueue;
rc = class_register(&memstick_host_class); rc = class_register(&memstick_host_class);
if (rc)
goto error_bus_unregister;
if (!rc)
return 0; return 0;
error_bus_unregister:
bus_unregister(&memstick_bus_type); bus_unregister(&memstick_bus_type);
error_destroy_workqueue:
destroy_workqueue(workqueue); destroy_workqueue(workqueue);
return rc; return rc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment