KASAN: slab-use-after-free Read in pvr2_context_set_notify
Subsystems (3)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 24be4d0b46bb arch/arm64/mm/fault: Fix undeclared variable .. git tree: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing console output: https://syzkaller.appspot.com/x/log.txt?x=11383b04a80000 kernel config: https://syzkaller.appspot.com/x/.config?x=f9122dc1c4589f4c dashboard link: https://syzkaller.appspot.com/bug?extid=621409285c4156a009b3 compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14e2e43ca80000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=109a3a90a80000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/b64cbb1118f1/disk-24be4d0b.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/568048c1dd0d/vmlinux-24be4d0b.xz
kernel image: https://storage.googleapis.com/syzbot-assets/84ac264152e7/bzImage-24be4d0b.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
==================================================================
BUG: KASAN: slab-use-after-free in pvr2_context_set_notify+0x2c4/0x310 drivers/media/usb/pvrusb2/pvrusb2-context.c:35 Read of size 4 at addr ffff88810eb986d8 by task kworker/0:0/7 CPU: 0 PID: 7 Comm: kworker/0:0 Not tainted 6.4.0-syzkaller-11311-g24be4d0b46bb #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/27/2023 Workqueue: usb_hub_wq hub_event Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106 print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:364 print_report mm/kasan/report.c:475 [inline] kasan_report+0x11d/0x130 mm/kasan/report.c:588 pvr2_context_set_notify+0x2c4/0x310 drivers/media/usb/pvrusb2/pvrusb2-context.c:35 pvr_disconnect+0x80/0xf0 drivers/media/usb/pvrusb2/pvrusb2-main.c:79 usb_unbind_interface+0x1dc/0x8e0 drivers/usb/core/driver.c:458 device_remove drivers/base/dd.c:569 [inline] device_remove+0x11f/0x170 drivers/base/dd.c:561 __device_release_driver drivers/base/dd.c:1270 [inline] device_release_driver_internal+0x443/0x610 drivers/base/dd.c:1293 bus_remove_device+0x22c/0x420 drivers/base/bus.c:574 device_del+0x399/0xa30 drivers/base/core.c:3814 usb_disable_device+0x360/0x7b0 drivers/usb/core/message.c:1420 usb_disconnect+0x2db/0x8a0 drivers/usb/core/hub.c:2253 hub_port_connect drivers/usb/core/hub.c:5261 [inline] hub_port_connect_change drivers/usb/core/hub.c:5566 [inline] port_event drivers/usb/core/hub.c:5726 [inline] hub_event+0x2073/0x4ed0 drivers/usb/core/hub.c:5808 process_one_work+0xa34/0x16f0 kernel/workqueue.c:2597 process_scheduled_works kernel/workqueue.c:2664 [inline] worker_thread+0x881/0x10c0 kernel/workqueue.c:2750 kthread+0x344/0x440 kernel/kthread.c:389 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 </TASK> Allocated by task 7: kasan_save_stack+0x22/0x40 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 ____kasan_kmalloc mm/kasan/common.c:374 [inline] __kasan_kmalloc+0x7b/0x90 mm/kasan/common.c:383 kmalloc include/linux/slab.h:579 [inline] kzalloc include/linux/slab.h:700 [inline] pvr2_context_create+0x53/0x2a0 drivers/media/usb/pvrusb2/pvrusb2-context.c:207 pvr_probe+0x25/0xe0 drivers/media/usb/pvrusb2/pvrusb2-main.c:54 usb_probe_interface+0x30f/0x960 drivers/usb/core/driver.c:396 call_driver_probe drivers/base/dd.c:579 [inline] really_probe+0x240/0xca0 drivers/base/dd.c:658 __driver_probe_device+0x1df/0x4b0 drivers/base/dd.c:798 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:828 __device_attach_driver+0x1d4/0x2e0 drivers/base/dd.c:956 bus_for_each_drv+0x149/0x1d0 drivers/base/bus.c:457 __device_attach+0x1e4/0x4b0 drivers/base/dd.c:1028 bus_probe_device+0x17c/0x1c0 drivers/base/bus.c:532 device_add+0x112d/0x1a40 drivers/base/core.c:3625 usb_set_configuration+0x1196/0x1bc0 drivers/usb/core/message.c:2211 usb_generic_driver_probe+0xcf/0x130 drivers/usb/core/generic.c:238 usb_probe_device+0xd8/0x2c0 drivers/usb/core/driver.c:293 call_driver_probe drivers/base/dd.c:579 [inline] really_probe+0x240/0xca0 drivers/base/dd.c:658 __driver_probe_device+0x1df/0x4b0 drivers/base/dd.c:798 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:828 __device_attach_driver+0x1d4/0x2e0 drivers/base/dd.c:956 bus_for_each_drv+0x149/0x1d0 drivers/base/bus.c:457 __device_attach+0x1e4/0x4b0 drivers/base/dd.c:1028 bus_probe_device+0x17c/0x1c0 drivers/base/bus.c:532 device_add+0x112d/0x1a40 drivers/base/core.c:3625 usb_new_device+0xcb2/0x19d0 drivers/usb/core/hub.c:2590 hub_port_connect drivers/usb/core/hub.c:5422 [inline] hub_port_connect_change drivers/usb/core/hub.c:5566 [inline] port_event drivers/usb/core/hub.c:5726 [inline] hub_event+0x2e3d/0x4ed0 drivers/usb/core/hub.c:5808 process_one_work+0xa34/0x16f0 kernel/workqueue.c:2597 process_scheduled_works kernel/workqueue.c:2664 [inline] worker_thread+0x881/0x10c0 kernel/workqueue.c:2750 kthread+0x344/0x440 kernel/kthread.c:389 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 Freed by task 892: kasan_save_stack+0x22/0x40 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:521 ____kasan_slab_free mm/kasan/common.c:236 [inline] ____kasan_slab_free+0x144/0x1b0 mm/kasan/common.c:200 kasan_slab_free include/linux/kasan.h:162 [inline] slab_free_hook mm/slub.c:1792 [inline] slab_free_freelist_hook mm/slub.c:1818 [inline] slab_free mm/slub.c:3801 [inline] __kmem_cache_free+0xa1/0x350 mm/slub.c:3814 pvr2_context_check drivers/media/usb/pvrusb2/pvrusb2-context.c:137 [inline] pvr2_context_thread_func+0x664/0x8e0 drivers/media/usb/pvrusb2/pvrusb2-context.c:158 kthread+0x344/0x440 kernel/kthread.c:389 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 The buggy address belongs to the object at ffff88810eb98600 which belongs to the cache kmalloc-256 of size 256
The buggy address is located 216 bytes inside of
freed 256-byte region [ffff88810eb98600, ffff88810eb98700)
The buggy address belongs to the physical page:
page:ffffea00043ae600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10eb98 head:ffffea00043ae600 order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0 anon flags: 0x200000000010200(slab|head|node=0|zone=2)page_type: 0xffffffff()
raw: 0200000000010200 ffff888100041b40 ffffea00043ae300 0000000000000003 raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected page_owner tracks the page as allocated page last allocated via order 1, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 7338785555, free_ts 0 set_page_owner include/linux/page_owner.h:31 [inline] post_alloc_hook+0x2db/0x350 mm/page_alloc.c:1570 prep_new_page mm/page_alloc.c:1577 [inline] get_page_from_freelist+0x13d5/0x2cb0 mm/page_alloc.c:3221 __alloc_pages+0x1cb/0x4a0 mm/page_alloc.c:4477 alloc_page_interleave+0x1e/0x1e0 mm/mempolicy.c:2112 alloc_pages+0x233/0x270 mm/mempolicy.c:2274 alloc_slab_page mm/slub.c:1862 [inline] allocate_slab+0x25f/0x390 mm/slub.c:2009 new_slab mm/slub.c:2062 [inline] ___slab_alloc+0xbc3/0x15d0 mm/slub.c:3215 __slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3314 __slab_alloc_node mm/slub.c:3367 [inline] slab_alloc_node mm/slub.c:3460 [inline] __kmem_cache_alloc_node+0x2c3/0x300 mm/slub.c:3509 __do_kmalloc_node mm/slab_common.c:984 [inline] __kmalloc_node_track_caller+0x4f/0x1a0 mm/slab_common.c:1005 __do_krealloc mm/slab_common.c:1373 [inline] krealloc+0x5e/0xf0 mm/slab_common.c:1406 add_sysfs_param+0xca/0x960 kernel/params.c:652 kernel_add_sysfs_param kernel/params.c:813 [inline] param_sysfs_builtin kernel/params.c:852 [inline] param_sysfs_builtin_init+0x241/0x440 kernel/params.c:986 do_one_initcall+0x105/0x630 init/main.c:1232 do_initcall_level init/main.c:1294 [inline] do_initcalls init/main.c:1310 [inline] do_basic_setup init/main.c:1329 [inline] kernel_init_freeable+0x649/0xb90 init/main.c:1546 kernel_init+0x1e/0x2c0 init/main.c:1437
page_owner free stack trace missing
Memory state around the buggy address:
ffff88810eb98580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88810eb98600: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88810eb98680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88810eb98700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88810eb98780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the bug is already fixed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to change bug's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the bug is a duplicate of another bug, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git ce9ecca0238b140b88f43859b211c9fdfd8e5b70
drivers/media/usb/pvrusb2/pvrusb2-context.c +7 -6
@@ -27,9 +27,16 @@ static int pvr2_context_cleaned_flag;static struct task_struct *pvr2_context_thread_ptr; +static int pvr2_context_shutok (void ) +{ +return pvr2_context_cleanup_flag && (pvr2_context_exist_first ==NULL ); +} + +static void pvr2_context_set_notify (struct pvr2_context *mp,int fl) {int signal_flag =0 ; +if (pvr2_context_shutok ())return ;mutex_lock (&pvr2_context_mutex);if (fl) {if (!mp->notify_flag) {
@@ -140,12 +147,6 @@ static void pvr2_context_check(struct pvr2_context *mp) } -static int pvr2_context_shutok (void ) -{ -return pvr2_context_cleanup_flag && (pvr2_context_exist_first ==NULL ); -} - -static int pvr2_context_thread_func (void *foo) {struct pvr2_context *mp;
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue:
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in pvr2_context_set_notify
pvrusb2: Important functionality might not be entirely working.
pvrusb2: Please consider contacting the driver author to help with further stabilization of the driver.
pvrusb2: **********
usb 1-1: USB disconnect, device number 102
pvrusb2: Device being rendered inoperable
==================================================================
BUG: KASAN: slab-use-after-free in pvr2_context_set_notify+0x2fa/0x350 drivers/media/usb/pvrusb2/pvrusb2-context.c:42 Read of size 4 at addr ffff8881093becd8 by task kworker/0:0/8 CPU: 0 PID: 8 Comm: kworker/0:0 Not tainted 6.6.0-rc2-syzkaller-dirty #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023 Workqueue: usb_hub_wq hub_event Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:364 [inline] print_report+0xc4/0x620 mm/kasan/report.c:475 kasan_report+0xda/0x110 mm/kasan/report.c:588 pvr2_context_set_notify+0x2fa/0x350 drivers/media/usb/pvrusb2/pvrusb2-context.c:42 pvr_disconnect+0x80/0xf0 drivers/media/usb/pvrusb2/pvrusb2-main.c:79 usb_unbind_interface+0x1dd/0x8d0 drivers/usb/core/driver.c:458 device_remove drivers/base/dd.c:569 [inline] device_remove+0x11f/0x170 drivers/base/dd.c:561 __device_release_driver drivers/base/dd.c:1272 [inline] device_release_driver_internal+0x44a/0x610 drivers/base/dd.c:1295 bus_remove_device+0x22c/0x420 drivers/base/bus.c:574 device_del+0x39a/0xa50 drivers/base/core.c:3813 usb_disable_device+0x36c/0x7f0 drivers/usb/core/message.c:1416 usb_disconnect+0x2e1/0x890 drivers/usb/core/hub.c:2252 hub_port_connect drivers/usb/core/hub.c:5280 [inline] hub_port_connect_change drivers/usb/core/hub.c:5580 [inline] port_event drivers/usb/core/hub.c:5740 [inline] hub_event+0x1be0/0x4f30 drivers/usb/core/hub.c:5822 process_one_work+0x884/0x15c0 kernel/workqueue.c:2630 process_scheduled_works kernel/workqueue.c:2703 [inline] worker_thread+0x8b9/0x1290 kernel/workqueue.c:2784 kthread+0x33c/0x440 kernel/kthread.c:388 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 </TASK> Allocated by task 8: kasan_save_stack+0x33/0x50 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 ____kasan_kmalloc mm/kasan/common.c:374 [inline] __kasan_kmalloc+0x87/0x90 mm/kasan/common.c:383 kmalloc include/linux/slab.h:599 [inline] kzalloc include/linux/slab.h:720 [inline] pvr2_context_create+0x53/0x2a0 drivers/media/usb/pvrusb2/pvrusb2-context.c:208 pvr_probe+0x25/0xe0 drivers/media/usb/pvrusb2/pvrusb2-main.c:54 usb_probe_interface+0x307/0x930 drivers/usb/core/driver.c:396 call_driver_probe drivers/base/dd.c:579 [inline] really_probe+0x234/0xc90 drivers/base/dd.c:658 __driver_probe_device+0x1de/0x4b0 drivers/base/dd.c:800 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:830 __device_attach_driver+0x1d4/0x300 drivers/base/dd.c:958 bus_for_each_drv+0x157/0x1d0 drivers/base/bus.c:457 __device_attach+0x1e8/0x4b0 drivers/base/dd.c:1030 bus_probe_device+0x17c/0x1c0 drivers/base/bus.c:532 device_add+0x117e/0x1aa0 drivers/base/core.c:3624 usb_set_configuration+0x10cb/0x1c40 drivers/usb/core/message.c:2207 usb_generic_driver_probe+0xca/0x130 drivers/usb/core/generic.c:238 usb_probe_device+0xda/0x2c0 drivers/usb/core/driver.c:293 call_driver_probe drivers/base/dd.c:579 [inline] really_probe+0x234/0xc90 drivers/base/dd.c:658 __driver_probe_device+0x1de/0x4b0 drivers/base/dd.c:800 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:830 __device_attach_driver+0x1d4/0x300 drivers/base/dd.c:958 bus_for_each_drv+0x157/0x1d0 drivers/base/bus.c:457 __device_attach+0x1e8/0x4b0 drivers/base/dd.c:1030 bus_probe_device+0x17c/0x1c0 drivers/base/bus.c:532 device_add+0x117e/0x1aa0 drivers/base/core.c:3624 usb_new_device+0xd80/0x1960 drivers/usb/core/hub.c:2589 hub_port_connect drivers/usb/core/hub.c:5440 [inline] hub_port_connect_change drivers/usb/core/hub.c:5580 [inline] port_event drivers/usb/core/hub.c:5740 [inline] hub_event+0x2e62/0x4f30 drivers/usb/core/hub.c:5822 process_one_work+0x884/0x15c0 kernel/workqueue.c:2630 process_scheduled_works kernel/workqueue.c:2703 [inline] worker_thread+0x8b9/0x1290 kernel/workqueue.c:2784 kthread+0x33c/0x440 kernel/kthread.c:388 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 Freed by task 901: kasan_save_stack+0x33/0x50 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:522 ____kasan_slab_free mm/kasan/common.c:236 [inline] ____kasan_slab_free+0x13c/0x190 mm/kasan/common.c:200 kasan_slab_free include/linux/kasan.h:164 [inline] slab_free_hook mm/slub.c:1800 [inline] slab_free_freelist_hook mm/slub.c:1826 [inline] slab_free mm/slub.c:3809 [inline] __kmem_cache_free+0xff/0x330 mm/slub.c:3822 pvr2_context_check drivers/media/usb/pvrusb2/pvrusb2-context.c:144 [inline] pvr2_context_thread_func+0x69d/0x960 drivers/media/usb/pvrusb2/pvrusb2-context.c:159 kthread+0x33c/0x440 kernel/kthread.c:388 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 The buggy address belongs to the object at ffff8881093bec00 which belongs to the cache kmalloc-256 of size 256
The buggy address is located 216 bytes inside of
freed 256-byte region [ffff8881093bec00, ffff8881093bed00)
The buggy address belongs to the physical page:
page:ffffea000424ef80 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1093be head:ffffea000424ef80 order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0 anon flags: 0x200000000000840(slab|head|node=0|zone=2)page_type: 0xffffffff()
raw: 0200000000000840 ffff888100041b40 0000000000000000 dead000000000001 raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected page_owner tracks the page as allocated page last allocated via order 1, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 8817323426, free_ts 0 set_page_owner include/linux/page_owner.h:31 [inline] post_alloc_hook+0x2cf/0x340 mm/page_alloc.c:1536 prep_new_page mm/page_alloc.c:1543 [inline] get_page_from_freelist+0x10e1/0x2fd0 mm/page_alloc.c:3170 __alloc_pages+0x1d0/0x4a0 mm/page_alloc.c:4426 alloc_page_interleave+0x1e/0x230 mm/mempolicy.c:2131 alloc_pages+0x22a/0x270 mm/mempolicy.c:2293 alloc_slab_page mm/slub.c:1870 [inline] allocate_slab+0x251/0x380 mm/slub.c:2017 new_slab mm/slub.c:2070 [inline] ___slab_alloc+0x8c7/0x1580 mm/slub.c:3223 __slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3322 __slab_alloc_node mm/slub.c:3375 [inline] slab_alloc_node mm/slub.c:3468 [inline] __kmem_cache_alloc_node+0x12c/0x310 mm/slub.c:3517 kmalloc_trace+0x25/0xe0 mm/slab_common.c:1114 kmalloc include/linux/slab.h:599 [inline] kzalloc include/linux/slab.h:720 [inline] bus_add_driver+0x92/0x630 drivers/base/bus.c:657 driver_register+0x15c/0x4a0 drivers/base/driver.c:246 usb_register_driver+0x24f/0x500 drivers/usb/core/driver.c:1062 do_one_initcall+0x117/0x630 init/main.c:1232 do_initcall_level init/main.c:1294 [inline] do_initcalls init/main.c:1310 [inline] do_basic_setup init/main.c:1329 [inline] kernel_init_freeable+0x5bd/0x8f0 init/main.c:1547 kernel_init+0x1c/0x2a0 init/main.c:1437
page_owner free stack trace missing
Memory state around the buggy address:
ffff8881093beb80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8881093bec00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8881093bec80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881093bed00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8881093bed80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================Tested on:
commit: ce9ecca0 Linux 6.6-rc2 git tree: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git console output: https://syzkaller.appspot.com/x/log.txt?x=13f01d0a680000 kernel config: https://syzkaller.appspot.com/x/.config?x=59eae8406319284a dashboard link: https://syzkaller.appspot.com/bug?extid=621409285c4156a009b3 compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=12ca2656680000
A message that is not in the archive (sent off-list or not yet received): [email protected]
syzbot
syzbotsyzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 633b47cb Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master console output: https://syzkaller.appspot.com/x/log.txt?x=103d5e12680000 kernel config: https://syzkaller.appspot.com/x/.config?x=acc0013b40e239a2 dashboard link: https://syzkaller.appspot.com/bug?extid=621409285c4156a009b3 compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=14381d0a680000
Note: testing is done by a robot and is best-effort only.
Good one, but make sure to test against Greg usb-testing tree!
Thanks,
- Ricardo
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 1053c4a4b8fcbd28386e80347e7c82d4d617e352
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue:
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in pvr2_context_set_notify
pvrusb2: Important functionality might not be entirely working.
pvrusb2: Please consider contacting the driver author to help with further stabilization of the driver.
pvrusb2: **********
usb 1-1: USB disconnect, device number 3
pvrusb2: Device being rendered inoperable
==================================================================
BUG: KASAN: slab-use-after-free in pvr2_context_set_notify+0x2c4/0x310 drivers/media/usb/pvrusb2/pvrusb2-context.c:35 Read of size 4 at addr ffff88812c3e68d8 by task kworker/0:2/699 CPU: 0 PID: 699 Comm: kworker/0:2 Not tainted 6.6.0-rc4-syzkaller-00064-g1053c4a4b8fc #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023 Workqueue: usb_hub_wq hub_event Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:364 [inline] print_report+0xc4/0x620 mm/kasan/report.c:475 kasan_report+0xda/0x110 mm/kasan/report.c:588 pvr2_context_set_notify+0x2c4/0x310 drivers/media/usb/pvrusb2/pvrusb2-context.c:35 pvr_disconnect+0x80/0xf0 drivers/media/usb/pvrusb2/pvrusb2-main.c:79 usb_unbind_interface+0x1dd/0x8d0 drivers/usb/core/driver.c:458 device_remove drivers/base/dd.c:569 [inline] device_remove+0x11f/0x170 drivers/base/dd.c:561 __device_release_driver drivers/base/dd.c:1272 [inline] device_release_driver_internal+0x44a/0x610 drivers/base/dd.c:1295 bus_remove_device+0x22c/0x420 drivers/base/bus.c:574 device_del+0x39a/0xa50 drivers/base/core.c:3813 usb_disable_device+0x36c/0x7f0 drivers/usb/core/message.c:1416 usb_disconnect+0x2e1/0x890 drivers/usb/core/hub.c:2252 hub_port_connect drivers/usb/core/hub.c:5280 [inline] hub_port_connect_change drivers/usb/core/hub.c:5580 [inline] port_event drivers/usb/core/hub.c:5740 [inline] hub_event+0x1be0/0x4f30 drivers/usb/core/hub.c:5822 process_one_work+0x884/0x15c0 kernel/workqueue.c:2630 process_scheduled_works kernel/workqueue.c:2703 [inline] worker_thread+0x8b9/0x1290 kernel/workqueue.c:2784 kthread+0x33c/0x440 kernel/kthread.c:388 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 </TASK> Allocated by task 699: kasan_save_stack+0x33/0x50 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 ____kasan_kmalloc mm/kasan/common.c:374 [inline] __kasan_kmalloc+0x87/0x90 mm/kasan/common.c:383 kmalloc include/linux/slab.h:599 [inline] kzalloc include/linux/slab.h:720 [inline] pvr2_context_create+0x53/0x2a0 drivers/media/usb/pvrusb2/pvrusb2-context.c:207 pvr_probe+0x25/0xe0 drivers/media/usb/pvrusb2/pvrusb2-main.c:54 usb_probe_interface+0x307/0x930 drivers/usb/core/driver.c:396 call_driver_probe drivers/base/dd.c:579 [inline] really_probe+0x234/0xc90 drivers/base/dd.c:658 __driver_probe_device+0x1de/0x4b0 drivers/base/dd.c:800 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:830 __device_attach_driver+0x1d4/0x300 drivers/base/dd.c:958 bus_for_each_drv+0x157/0x1d0 drivers/base/bus.c:457 __device_attach+0x1e8/0x4b0 drivers/base/dd.c:1030 bus_probe_device+0x17c/0x1c0 drivers/base/bus.c:532 device_add+0x117e/0x1aa0 drivers/base/core.c:3624 usb_set_configuration+0x10cb/0x1c40 drivers/usb/core/message.c:2207 usb_generic_driver_probe+0xca/0x130 drivers/usb/core/generic.c:238 usb_probe_device+0xda/0x2c0 drivers/usb/core/driver.c:293 call_driver_probe drivers/base/dd.c:579 [inline] really_probe+0x234/0xc90 drivers/base/dd.c:658 __driver_probe_device+0x1de/0x4b0 drivers/base/dd.c:800 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:830 __device_attach_driver+0x1d4/0x300 drivers/base/dd.c:958 bus_for_each_drv+0x157/0x1d0 drivers/base/bus.c:457 __device_attach+0x1e8/0x4b0 drivers/base/dd.c:1030 bus_probe_device+0x17c/0x1c0 drivers/base/bus.c:532 device_add+0x117e/0x1aa0 drivers/base/core.c:3624 usb_new_device+0xd80/0x1960 drivers/usb/core/hub.c:2589 hub_port_connect drivers/usb/core/hub.c:5440 [inline] hub_port_connect_change drivers/usb/core/hub.c:5580 [inline] port_event drivers/usb/core/hub.c:5740 [inline] hub_event+0x2e62/0x4f30 drivers/usb/core/hub.c:5822 process_one_work+0x884/0x15c0 kernel/workqueue.c:2630 process_scheduled_works kernel/workqueue.c:2703 [inline] worker_thread+0x8b9/0x1290 kernel/workqueue.c:2784 kthread+0x33c/0x440 kernel/kthread.c:388 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 Freed by task 902: kasan_save_stack+0x33/0x50 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:522 ____kasan_slab_free mm/kasan/common.c:236 [inline] ____kasan_slab_free+0x13c/0x190 mm/kasan/common.c:200 kasan_slab_free include/linux/kasan.h:164 [inline] slab_free_hook mm/slub.c:1800 [inline] slab_free_freelist_hook mm/slub.c:1826 [inline] slab_free mm/slub.c:3809 [inline] __kmem_cache_free+0xff/0x330 mm/slub.c:3822 pvr2_context_check drivers/media/usb/pvrusb2/pvrusb2-context.c:137 [inline] pvr2_context_thread_func+0x69d/0x960 drivers/media/usb/pvrusb2/pvrusb2-context.c:158 kthread+0x33c/0x440 kernel/kthread.c:388 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 The buggy address belongs to the object at ffff88812c3e6800 which belongs to the cache kmalloc-256 of size 256
The buggy address is located 216 bytes inside of
freed 256-byte region [ffff88812c3e6800, ffff88812c3e6900)
The buggy address belongs to the physical page:
page:ffffea0004b0f980 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x12c3e6 head:ffffea0004b0f980 order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000840(slab|head|node=0|zone=2)page_type: 0xffffffff()
raw: 0200000000000840 ffff888100041b40 ffffea0004722a80 dead000000000004
raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Unmovable, gfp_mask 0x1d20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 699, tgid 699 (kworker/0:2), ts 149486728006, free_ts 149464487231
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x2cf/0x340 mm/page_alloc.c:1536
prep_new_page mm/page_alloc.c:1543 [inline]
get_page_from_freelist+0x10e1/0x2fd0 mm/page_alloc.c:3170
__alloc_pages+0x1d0/0x4a0 mm/page_alloc.c:4426
alloc_pages+0x1a9/0x270 mm/mempolicy.c:2297
alloc_slab_page mm/slub.c:1870 [inline]
allocate_slab+0x251/0x380 mm/slub.c:2017
new_slab mm/slub.c:2070 [inline]
___slab_alloc+0x8c7/0x1580 mm/slub.c:3223
__slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3322
__slab_alloc_node mm/slub.c:3375 [inline]
slab_alloc_node mm/slub.c:3468 [inline]
__kmem_cache_alloc_node+0x12c/0x310 mm/slub.c:3517
kmalloc_trace+0x25/0xe0 mm/slab_common.c:1114
kmalloc include/linux/slab.h:599 [inline]
kzalloc include/linux/slab.h:720 [inline]
pvr2_context_create+0x53/0x2a0 drivers/media/usb/pvrusb2/pvrusb2-context.c:207
pvr_probe+0x25/0xe0 drivers/media/usb/pvrusb2/pvrusb2-main.c:54
usb_probe_interface+0x307/0x930 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:579 [inline]
really_probe+0x234/0xc90 drivers/base/dd.c:658
__driver_probe_device+0x1de/0x4b0 drivers/base/dd.c:800
driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:830
__device_attach_driver+0x1d4/0x300 drivers/base/dd.c:958
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1136 [inline]
free_unref_page_prepare+0x460/0xa20 mm/page_alloc.c:2312
free_unref_page+0x33/0x2c0 mm/page_alloc.c:2405
qlink_free mm/kasan/quarantine.c:166 [inline]
qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:185
kasan_quarantine_reduce+0x18e/0x1d0 mm/kasan/quarantine.c:292
__kasan_slab_alloc+0x4a/0x70 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:188 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slub.c:3478 [inline]
__kmem_cache_alloc_node+0x190/0x310 mm/slub.c:3517
__do_kmalloc_node mm/slab_common.c:1022 [inline]
__kmalloc+0x4f/0x100 mm/slab_common.c:1036
kmalloc include/linux/slab.h:603 [inline]
tomoyo_realpath_from_path+0xb9/0x710 security/tomoyo/realpath.c:251
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_number_perm+0x241/0x580 security/tomoyo/file.c:723
security_file_ioctl+0x72/0xb0 security/security.c:2647
__do_sys_ioctl fs/ioctl.c:865 [inline]
__se_sys_ioctl fs/ioctl.c:857 [inline]
__x64_sys_ioctl+0xbb/0x210 fs/ioctl.c:857
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
Memory state around the buggy address:
ffff88812c3e6780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88812c3e6800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88812c3e6880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88812c3e6900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88812c3e6980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================Tested on:
commit: 1053c4a4 Revert "usb: gadget: uvc: stop pump thread on.. git tree: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git console output: https://syzkaller.appspot.com/x/log.txt?x=1472423a680000 kernel config: https://syzkaller.appspot.com/x/.config?x=a5e01246f94ceed9 dashboard link: https://syzkaller.appspot.com/bug?extid=621409285c4156a009b3 compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git ce9ecca0238b140b88f43859b211c9fdfd8e5b70
From cf7c3b08f80c4cdb7dd08cb977f29d41efebcf79 Mon Sep 17 00:00:00 2001
From: "Ricardo B. Marliere" <[email protected]>
Date: Thu, 12 Oct 2023 18:26:47 -0300
Subject: [PATCH] media: pvrusb2: fix use after free on context disconnection
Upon module load, a kthread is created targeting the pvr2_context_thread_func function, which may call pvr2_context_destroy and thus call kfree() on the context object. However, that might happen before the usb hub_event handler is able to notify the driver. This patch adds a sanity check before the invalid read reported by syzbot, within the context disconnection call stack.
--- drivers/media/usb/pvrusb2/pvrusb2-context.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-context.c +2 -1
@@ -268,7 +268,8 @@ void pvr2_context_disconnect(struct pvr2_context *mp) {pvr2_hdw_disconnect (mp->hdw); mp->disconnect_flag = !0 ; -pvr2_context_notify (mp); +if (!pvr2_context_shutok ()) +pvr2_context_notify (mp); }
Signature · 1 line
2.42.0
syzbot
syzbotsyzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: ce9ecca0 Linux 6.6-rc2 git tree: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git console output: https://syzkaller.appspot.com/x/log.txt?x=10be5209680000 kernel config: https://syzkaller.appspot.com/x/.config?x=59eae8406319284a dashboard link: https://syzkaller.appspot.com/bug?extid=621409285c4156a009b3 compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=131dd84d680000
Note: testing is done by a robot and is best-effort only.