Skip to content

Commit d72a857

Browse files
Wang Haigregkh
authored andcommitted
memstick: Fix error cleanup path of memstick_init
[ Upstream commit 65f1a0d ] 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: baf8532 ("memstick: initial commit for Sony MemoryStick support") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Wang Hai <wanghai26@huawei.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 63d1bc1 commit d72a857

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/memstick/core/memstick.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,18 @@ static int __init memstick_init(void)
629629
return -ENOMEM;
630630

631631
rc = bus_register(&memstick_bus_type);
632-
if (!rc)
633-
rc = class_register(&memstick_host_class);
632+
if (rc)
633+
goto error_destroy_workqueue;
634634

635-
if (!rc)
636-
return 0;
635+
rc = class_register(&memstick_host_class);
636+
if (rc)
637+
goto error_bus_unregister;
638+
639+
return 0;
637640

641+
error_bus_unregister:
638642
bus_unregister(&memstick_bus_type);
643+
error_destroy_workqueue:
639644
destroy_workqueue(workqueue);
640645

641646
return rc;

0 commit comments

Comments
 (0)