]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.181/media-cpia2-fix-use-after-free-in-cpia2_exit.patch
Linux 4.9.181
[thirdparty/kernel/stable-queue.git] / releases / 4.4.181 / media-cpia2-fix-use-after-free-in-cpia2_exit.patch
1 From dea37a97265588da604c6ba80160a287b72c7bfd Mon Sep 17 00:00:00 2001
2 From: YueHaibing <yuehaibing@huawei.com>
3 Date: Wed, 6 Mar 2019 07:45:08 -0500
4 Subject: media: cpia2: Fix use-after-free in cpia2_exit
5
6 From: YueHaibing <yuehaibing@huawei.com>
7
8 commit dea37a97265588da604c6ba80160a287b72c7bfd upstream.
9
10 Syzkaller report this:
11
12 BUG: KASAN: use-after-free in sysfs_remove_file_ns+0x5f/0x70 fs/sysfs/file.c:468
13 Read of size 8 at addr ffff8881f59a6b70 by task syz-executor.0/8363
14
15 CPU: 0 PID: 8363 Comm: syz-executor.0 Not tainted 5.0.0-rc8+ #3
16 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
17 Call Trace:
18 __dump_stack lib/dump_stack.c:77 [inline]
19 dump_stack+0xfa/0x1ce lib/dump_stack.c:113
20 print_address_description+0x65/0x270 mm/kasan/report.c:187
21 kasan_report+0x149/0x18d mm/kasan/report.c:317
22 sysfs_remove_file_ns+0x5f/0x70 fs/sysfs/file.c:468
23 sysfs_remove_file include/linux/sysfs.h:519 [inline]
24 driver_remove_file+0x40/0x50 drivers/base/driver.c:122
25 usb_remove_newid_files drivers/usb/core/driver.c:212 [inline]
26 usb_deregister+0x12a/0x3b0 drivers/usb/core/driver.c:1005
27 cpia2_exit+0xa/0x16 [cpia2]
28 __do_sys_delete_module kernel/module.c:1018 [inline]
29 __se_sys_delete_module kernel/module.c:961 [inline]
30 __x64_sys_delete_module+0x3dc/0x5e0 kernel/module.c:961
31 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
32 entry_SYSCALL_64_after_hwframe+0x49/0xbe
33 RIP: 0033:0x462e99
34 Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
35 RSP: 002b:00007f86f3754c58 EFLAGS: 00000246 ORIG_RAX: 00000000000000b0
36 RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99
37 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000300
38 RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000
39 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f86f37556bc
40 R13: 00000000004bcca9 R14: 00000000006f6b48 R15: 00000000ffffffff
41
42 Allocated by task 8363:
43 set_track mm/kasan/common.c:85 [inline]
44 __kasan_kmalloc.constprop.3+0xa0/0xd0 mm/kasan/common.c:495
45 kmalloc include/linux/slab.h:545 [inline]
46 kzalloc include/linux/slab.h:740 [inline]
47 bus_add_driver+0xc0/0x610 drivers/base/bus.c:651
48 driver_register+0x1bb/0x3f0 drivers/base/driver.c:170
49 usb_register_driver+0x267/0x520 drivers/usb/core/driver.c:965
50 0xffffffffc1b4817c
51 do_one_initcall+0xfa/0x5ca init/main.c:887
52 do_init_module+0x204/0x5f6 kernel/module.c:3460
53 load_module+0x66b2/0x8570 kernel/module.c:3808
54 __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
55 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
56 entry_SYSCALL_64_after_hwframe+0x49/0xbe
57
58 Freed by task 8363:
59 set_track mm/kasan/common.c:85 [inline]
60 __kasan_slab_free+0x130/0x180 mm/kasan/common.c:457
61 slab_free_hook mm/slub.c:1430 [inline]
62 slab_free_freelist_hook mm/slub.c:1457 [inline]
63 slab_free mm/slub.c:3005 [inline]
64 kfree+0xe1/0x270 mm/slub.c:3957
65 kobject_cleanup lib/kobject.c:662 [inline]
66 kobject_release lib/kobject.c:691 [inline]
67 kref_put include/linux/kref.h:67 [inline]
68 kobject_put+0x146/0x240 lib/kobject.c:708
69 bus_remove_driver+0x10e/0x220 drivers/base/bus.c:732
70 driver_unregister+0x6c/0xa0 drivers/base/driver.c:197
71 usb_register_driver+0x341/0x520 drivers/usb/core/driver.c:980
72 0xffffffffc1b4817c
73 do_one_initcall+0xfa/0x5ca init/main.c:887
74 do_init_module+0x204/0x5f6 kernel/module.c:3460
75 load_module+0x66b2/0x8570 kernel/module.c:3808
76 __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
77 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
78 entry_SYSCALL_64_after_hwframe+0x49/0xbe
79
80 The buggy address belongs to the object at ffff8881f59a6b40
81 which belongs to the cache kmalloc-256 of size 256
82 The buggy address is located 48 bytes inside of
83 256-byte region [ffff8881f59a6b40, ffff8881f59a6c40)
84 The buggy address belongs to the page:
85 page:ffffea0007d66980 count:1 mapcount:0 mapping:ffff8881f6c02e00 index:0x0
86 flags: 0x2fffc0000000200(slab)
87 raw: 02fffc0000000200 dead000000000100 dead000000000200 ffff8881f6c02e00
88 raw: 0000000000000000 00000000800c000c 00000001ffffffff 0000000000000000
89 page dumped because: kasan: bad access detected
90
91 Memory state around the buggy address:
92 ffff8881f59a6a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
93 ffff8881f59a6a80: 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc
94 >ffff8881f59a6b00: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
95 ^
96 ffff8881f59a6b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
97 ffff8881f59a6c00: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
98
99 cpia2_init does not check return value of cpia2_init, if it failed
100 in usb_register_driver, there is already cleanup using driver_unregister.
101 No need call cpia2_usb_cleanup on module exit.
102
103 Reported-by: Hulk Robot <hulkci@huawei.com>
104 Signed-off-by: YueHaibing <yuehaibing@huawei.com>
105 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
106 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
107 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
108
109 ---
110 drivers/media/usb/cpia2/cpia2_v4l.c | 3 +--
111 1 file changed, 1 insertion(+), 2 deletions(-)
112
113 --- a/drivers/media/usb/cpia2/cpia2_v4l.c
114 +++ b/drivers/media/usb/cpia2/cpia2_v4l.c
115 @@ -1248,8 +1248,7 @@ static int __init cpia2_init(void)
116 LOG("%s v%s\n",
117 ABOUT, CPIA_VERSION);
118 check_parameters();
119 - cpia2_usb_init();
120 - return 0;
121 + return cpia2_usb_init();
122 }
123
124