syzbot


KASAN: use-after-free Read in em28xx_close_extension

Status: upstream: reported C repro on 2021/07/14 14:27
Reported-by: syzbot+005037419ebdf14e1d87@syzkaller.appspotmail.com
First crash: 443d, last: 237d

Cause bisection: introduced by (bisect log) :
commit ac5688637144644f06ed1f3c6d4dd8bb7db96020
Author: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
Date: Tue May 4 18:32:49 2021 +0000

  media: em28xx: Fix possible memory leak of em28xx struct

Crash: KASAN: use-after-free Read in em28xx_close_extension (log)
Repro: C syz .config

Fix bisection: fixed by (bisect log) :
commit 0766ec82e5fb26fc5dc6d592bc61865608bdc651
Author: Stephen Brennan <stephen.s.brennan@oracle.com>
Date: Wed Sep 1 17:51:41 2021 +0000

  namei: Fix use after free in kern_path_locked

Patch testing requests:
Created Duration User Patch Repo Result
2022/09/21 00:29 18m upstream OK log
2022/09/20 22:29 18m upstream OK log
2021/07/15 10:05 18m mudongliangabcd@gmail.com patch upstream OK

Sample crash report:
em28xx 1-1:0.179: Closing input extension
em28xx 1-1:0.179: Freeing device
==================================================================
BUG: KASAN: use-after-free in __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42
Read of size 8 at addr ffff888040e68258 by task kworker/0:3/3160

CPU: 0 PID: 3160 Comm: kworker/0:3 Not tainted 5.14.0-rc3-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: usb_hub_wq hub_event
Call Trace:
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105
 print_address_description.constprop.0.cold+0x6c/0x2d6 mm/kasan/report.c:233
 __kasan_report mm/kasan/report.c:419 [inline]
 kasan_report.cold+0x83/0xdf mm/kasan/report.c:436
 __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42
 __list_del_entry include/linux/list.h:132 [inline]
 list_del include/linux/list.h:146 [inline]
 em28xx_close_extension+0x10b/0x2a0 drivers/media/usb/em28xx/em28xx-core.c:1146
 em28xx_usb_disconnect.cold+0x14b/0x237 drivers/media/usb/em28xx/em28xx-cards.c:4140
 usb_unbind_interface+0x1d8/0x8d0 drivers/usb/core/driver.c:458
 __device_release_driver+0x3bd/0x6f0 drivers/base/dd.c:1201
 device_release_driver_internal drivers/base/dd.c:1232 [inline]
 device_release_driver+0x26/0x40 drivers/base/dd.c:1255
 bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
 device_del+0x502/0xd40 drivers/base/core.c:3542
 usb_disable_device+0x35b/0x7b0 drivers/usb/core/message.c:1419
 usb_disconnect.cold+0x27a/0x78e drivers/usb/core/hub.c:2225
 hub_port_connect drivers/usb/core/hub.c:5199 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5488 [inline]
 port_event drivers/usb/core/hub.c:5634 [inline]
 hub_event+0x1c9c/0x4330 drivers/usb/core/hub.c:5716
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
 process_scheduled_works kernel/workqueue.c:2338 [inline]
 worker_thread+0x85c/0x11f0 kernel/workqueue.c:2424
 kthread+0x3e5/0x4d0 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Allocated by task 3160:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:434 [inline]
 ____kasan_kmalloc mm/kasan/common.c:513 [inline]
 ____kasan_kmalloc mm/kasan/common.c:472 [inline]
 __kasan_kmalloc+0x98/0xc0 mm/kasan/common.c:522
 kasan_kmalloc include/linux/kasan.h:264 [inline]
 kmem_cache_alloc_trace+0x1e4/0x480 mm/slab.c:3575
 kmalloc include/linux/slab.h:591 [inline]
 kzalloc include/linux/slab.h:721 [inline]
 em28xx_usb_probe+0x218/0xd30 drivers/media/usb/em28xx/em28xx-cards.c:3855
 usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
 call_driver_probe drivers/base/dd.c:517 [inline]
 really_probe+0x23c/0xcd0 drivers/base/dd.c:595
 __driver_probe_device+0x338/0x4d0 drivers/base/dd.c:747
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:777
 __device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:894
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x228/0x4a0 drivers/base/dd.c:965
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xc2f/0x2180 drivers/base/core.c:3354
 usb_set_configuration+0x113a/0x1910 drivers/usb/core/message.c:2170
 usb_generic_driver_probe+0xba/0x100 drivers/usb/core/generic.c:238
 usb_probe_device+0xd9/0x2c0 drivers/usb/core/driver.c:293
 call_driver_probe drivers/base/dd.c:517 [inline]
 really_probe+0x23c/0xcd0 drivers/base/dd.c:595
 __driver_probe_device+0x338/0x4d0 drivers/base/dd.c:747
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:777
 __device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:894
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x228/0x4a0 drivers/base/dd.c:965
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xc2f/0x2180 drivers/base/core.c:3354
 usb_new_device.cold+0x63f/0x108e drivers/usb/core/hub.c:2563
 hub_port_connect drivers/usb/core/hub.c:5348 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5488 [inline]
 port_event drivers/usb/core/hub.c:5634 [inline]
 hub_event+0x2357/0x4330 drivers/usb/core/hub.c:5716
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422
 kthread+0x3e5/0x4d0 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Freed by task 3160:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free mm/kasan/common.c:328 [inline]
 __kasan_slab_free+0xcd/0x100 mm/kasan/common.c:374
 kasan_slab_free include/linux/kasan.h:230 [inline]
 __cache_free mm/slab.c:3445 [inline]
 kfree+0x106/0x2c0 mm/slab.c:3803
 __refcount_sub_and_test include/linux/refcount.h:282 [inline]
 __refcount_dec_and_test include/linux/refcount.h:315 [inline]
 refcount_dec_and_test include/linux/refcount.h:333 [inline]
 kref_put.constprop.0.isra.0+0x3d/0x7e include/linux/kref.h:64
 em28xx_ir_fini.cold+0x7c/0x120 drivers/media/usb/em28xx/em28xx-input.c:875
 em28xx_close_extension+0xc9/0x2a0 drivers/media/usb/em28xx/em28xx-core.c:1143
 em28xx_usb_disconnect.cold+0x14b/0x237 drivers/media/usb/em28xx/em28xx-cards.c:4140
 usb_unbind_interface+0x1d8/0x8d0 drivers/usb/core/driver.c:458
 __device_release_driver+0x3bd/0x6f0 drivers/base/dd.c:1201
 device_release_driver_internal drivers/base/dd.c:1232 [inline]
 device_release_driver+0x26/0x40 drivers/base/dd.c:1255
 bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
 device_del+0x502/0xd40 drivers/base/core.c:3542
 usb_disable_device+0x35b/0x7b0 drivers/usb/core/message.c:1419
 usb_disconnect.cold+0x27a/0x78e drivers/usb/core/hub.c:2225
 hub_port_connect drivers/usb/core/hub.c:5199 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5488 [inline]
 port_event drivers/usb/core/hub.c:5634 [inline]
 hub_event+0x1c9c/0x4330 drivers/usb/core/hub.c:5716
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
 process_scheduled_works kernel/workqueue.c:2338 [inline]
 worker_thread+0x85c/0x11f0 kernel/workqueue.c:2424
 kthread+0x3e5/0x4d0 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Last potentially related work creation:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_record_aux_stack+0xa4/0xd0 mm/kasan/generic.c:348
 insert_work+0x48/0x370 kernel/workqueue.c:1332
 __queue_work+0x5c1/0xed0 kernel/workqueue.c:1498
 queue_work_on+0xee/0x110 kernel/workqueue.c:1525
 queue_work include/linux/workqueue.h:507 [inline]
 schedule_work include/linux/workqueue.h:568 [inline]
 request_modules drivers/media/usb/em28xx/em28xx-cards.c:3430 [inline]
 em28xx_usb_probe.cold+0x15e9/0x2582 drivers/media/usb/em28xx/em28xx-cards.c:4088
 usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
 call_driver_probe drivers/base/dd.c:517 [inline]
 really_probe+0x23c/0xcd0 drivers/base/dd.c:595
 __driver_probe_device+0x338/0x4d0 drivers/base/dd.c:747
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:777
 __device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:894
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x228/0x4a0 drivers/base/dd.c:965
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xc2f/0x2180 drivers/base/core.c:3354
 usb_set_configuration+0x113a/0x1910 drivers/usb/core/message.c:2170
 usb_generic_driver_probe+0xba/0x100 drivers/usb/core/generic.c:238
 usb_probe_device+0xd9/0x2c0 drivers/usb/core/driver.c:293
 call_driver_probe drivers/base/dd.c:517 [inline]
 really_probe+0x23c/0xcd0 drivers/base/dd.c:595
 __driver_probe_device+0x338/0x4d0 drivers/base/dd.c:747
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:777
 __device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:894
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x228/0x4a0 drivers/base/dd.c:965
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xc2f/0x2180 drivers/base/core.c:3354
 usb_new_device.cold+0x63f/0x108e drivers/usb/core/hub.c:2563
 hub_port_connect drivers/usb/core/hub.c:5348 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5488 [inline]
 port_event drivers/usb/core/hub.c:5634 [inline]
 hub_event+0x2357/0x4330 drivers/usb/core/hub.c:5716
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2276
 worker_thread+0x658/0x11f0 kernel/workqueue.c:2422
 kthread+0x3e5/0x4d0 kernel/kthread.c:319
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff888040e68000
 which belongs to the cache kmalloc-16k of size 16384
The buggy address is located 600 bytes inside of
 16384-byte region [ffff888040e68000, ffff888040e6c000)
The buggy address belongs to the page:
page:ffffea0001039a00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x40e68
head:ffffea0001039a00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffffea0001039808 ffffea0001039c08 ffff888010840b00
raw: 0000000000000000 ffff888040e68000 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0x2420c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_THISNODE), pid 3160, ts 86427781608, free_ts 0
 prep_new_page mm/page_alloc.c:2436 [inline]
 get_page_from_freelist+0xa72/0x2f80 mm/page_alloc.c:4169
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5391
 __alloc_pages_node include/linux/gfp.h:570 [inline]
 kmem_getpages mm/slab.c:1377 [inline]
 cache_grow_begin+0x75/0x460 mm/slab.c:2593
 cache_alloc_refill+0x27f/0x380 mm/slab.c:2965
 ____cache_alloc mm/slab.c:3048 [inline]
 ____cache_alloc mm/slab.c:3031 [inline]
 __do_cache_alloc mm/slab.c:3275 [inline]
 slab_alloc mm/slab.c:3316 [inline]
 kmem_cache_alloc_trace+0x38c/0x480 mm/slab.c:3573
 kmalloc include/linux/slab.h:591 [inline]
 kzalloc include/linux/slab.h:721 [inline]
 em28xx_usb_probe+0x218/0xd30 drivers/media/usb/em28xx/em28xx-cards.c:3855
 usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
 call_driver_probe drivers/base/dd.c:517 [inline]
 really_probe+0x23c/0xcd0 drivers/base/dd.c:595
 __driver_probe_device+0x338/0x4d0 drivers/base/dd.c:747
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:777
 __device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:894
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x228/0x4a0 drivers/base/dd.c:965
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xc2f/0x2180 drivers/base/core.c:3354
 usb_set_configuration+0x113a/0x1910 drivers/usb/core/message.c:2170
page_owner free stack trace missing

Memory state around the buggy address:
 ffff888040e68100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888040e68180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888040e68200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                    ^
 ffff888040e68280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888040e68300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (20):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-selinux-root 2021/07/28 07:45 upstream 7d549995d4e0 17d6ab15 .config log report syz C KASAN: use-after-free Read in em28xx_close_extension
ci-upstream-kasan-gce 2021/08/21 10:15 upstream fa54d366a6e4 b599f2fc .config log report syz C KASAN: use-after-free Read in em28xx_close_extension
ci-upstream-kasan-gce 2021/07/10 15:05 upstream 3dbdb38e2869 8f5a7b8c .config log report syz C KASAN: use-after-free Read in em28xx_close_extension
ci-upstream-kasan-gce 2021/07/10 14:22 upstream 3dbdb38e2869 8f5a7b8c .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2022/02/01 08:08 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 554237f2bb62 6b7c57fe .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2022/01/24 11:08 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing e783362eb54c 214351e1 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2022/01/09 05:38 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing cbb4f5f43599 2ca0d385 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/12/20 11:29 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 236c9ad1f870 021b36cb .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/12/20 06:55 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing f2b42379c576 44068e19 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/11/28 06:51 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing c4bc515d73b5 63eeac02 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/11/28 01:56 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing c4bc515d73b5 63eeac02 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/11/23 00:23 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 4616dddcfaf7 545ab074 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/11/12 11:43 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 5833291ab6de 75b04091 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/08/31 11:58 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 9c1587d99f93 8f58a0ef .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/08/28 16:40 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 9c1587d99f93 d5a29e53 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/08/05 02:11 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 64cd4271ea8e b97d64c9 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/07/26 04:32 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 8e6cb5d27e82 4d1b57d4 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/07/24 03:06 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 8e6cb5d27e82 bc5f1d88 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/07/19 13:11 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 97db1b081e12 e6a17580 .config log report info KASAN: use-after-free Read in em28xx_close_extension
ci2-upstream-usb 2021/07/13 20:16 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 97db1b081e12 70168d5c .config log report info KASAN: use-after-free Read in em28xx_close_extension
* Struck through repros no longer work on HEAD.