[v6.1] KASAN: use-after-free Read in __usb_hcd_giveback_urb

0 views
Skip to first unread message

syzbot

unread,
Apr 5, 2024, 11:35:20 PMApr 5
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 347385861c50 Linux 6.1.84
git tree: linux-6.1.y
console output: https://syzkaller.appspot.com/x/log.txt?x=1511c52d180000
kernel config: https://syzkaller.appspot.com/x/.config?x=40dfd13b04bfc094
dashboard link: https://syzkaller.appspot.com/bug?extid=94936196e16d5ad44ed6
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/73d2a8622b6e/disk-34738586.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/e7bc2e0101a7/vmlinux-34738586.xz
kernel image: https://storage.googleapis.com/syzbot-assets/7b96d1168608/bzImage-34738586.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+949361...@syzkaller.appspotmail.com

xpad 2-1:179.65: xpad_irq_in - usb_submit_urb failed with result -19
xpad 2-1:179.65: xpad_irq_out - usb_submit_urb failed with result -19
==================================================================
BUG: KASAN: use-after-free in register_lock_class+0x8e8/0x990 kernel/locking/lockdep.c:1331
Read of size 1 at addr ffff888021668091 by task syz-executor.3/17926

CPU: 1 PID: 17926 Comm: syz-executor.3 Not tainted 6.1.84-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
Call Trace:
<IRQ>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
print_address_description mm/kasan/report.c:284 [inline]
print_report+0x15f/0x4f0 mm/kasan/report.c:395
kasan_report+0x136/0x160 mm/kasan/report.c:495
register_lock_class+0x8e8/0x990 kernel/locking/lockdep.c:1331
__lock_acquire+0xd3/0x1f80 kernel/locking/lockdep.c:4928
lock_acquire+0x1f8/0x5a0 kernel/locking/lockdep.c:5662
__raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
_raw_spin_lock_irqsave+0xd1/0x120 kernel/locking/spinlock.c:162
__wake_up_common_lock kernel/sched/wait.c:137 [inline]
__wake_up+0xfd/0x1c0 kernel/sched/wait.c:160
__usb_hcd_giveback_urb+0x3a8/0x530 drivers/usb/core/hcd.c:1678
dummy_timer+0x8ad/0x3200 drivers/usb/gadget/udc/dummy_hcd.c:1988
call_timer_fn+0x1ad/0x6b0 kernel/time/timer.c:1504
expire_timers kernel/time/timer.c:1549 [inline]
__run_timers+0x67c/0x890 kernel/time/timer.c:1820
run_timer_softirq+0x63/0xf0 kernel/time/timer.c:1833
__do_softirq+0x2e9/0xa4c kernel/softirq.c:571
invoke_softirq kernel/softirq.c:445 [inline]
__irq_exit_rcu+0x155/0x240 kernel/softirq.c:650
irq_exit_rcu+0x5/0x20 kernel/softirq.c:662
sysvec_apic_timer_interrupt+0x91/0xb0 arch/x86/kernel/apic/apic.c:1106
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x16/0x20 arch/x86/include/asm/idtentry.h:653
RIP: 0010:check_kcov_mode kernel/kcov.c:184 [inline]
RIP: 0010:write_comp_data kernel/kcov.c:236 [inline]
RIP: 0010:__sanitizer_cov_trace_const_cmp8+0x30/0x80 kernel/kcov.c:311
Code: 8b 0d 64 e4 77 7e 65 8b 05 65 e4 77 7e a9 00 01 ff 00 74 10 a9 00 01 00 00 74 57 83 b9 1c 16 00 00 00 74 4e 8b 81 f8 15 00 00 <83> f8 03 75 43 48 8b 91 00 16 00 00 44 8b 89 fc 15 00 00 49 c1 e1
RSP: 0018:ffffc9000561f590 EFLAGS: 00000246
RAX: 0000000000000002 RBX: 00fff8c000001042 RCX: ffff888013b49dc0
RDX: ffffc9001603a000 RSI: 00fff8c000001042 RDI: ffffffffffffffff
RBP: dffffc0000000000 R08: ffffffff81eca036 R09: fffffbfff2093045
R10: 0000000000000000 R11: dffffc0000000001 R12: ffffea00003f6088
R13: ffff888013e34c90 R14: 0000000000000001 R15: ffffea00003f6080
PagePoisoned include/linux/page-flags.h:304 [inline]
PageSlab include/linux/page-flags.h:487 [inline]
page_table_check_clear+0xd6/0x720 mm/page_table_check.c:73
zap_pte_range mm/memory.c:1435 [inline]
zap_pmd_range mm/memory.c:1574 [inline]
zap_pud_range mm/memory.c:1603 [inline]
zap_p4d_range mm/memory.c:1624 [inline]
unmap_page_range+0x1b4a/0x2740 mm/memory.c:1645
unmap_vmas+0x48b/0x640 mm/memory.c:1730
unmap_region+0x1fc/0x2f0 mm/mmap.c:2329
do_mas_align_munmap+0xec8/0x15f0 mm/mmap.c:2582
do_mas_munmap+0x246/0x2b0 mm/mmap.c:2640
__vm_munmap+0x268/0x370 mm/mmap.c:2917
__do_sys_munmap mm/mmap.c:2942 [inline]
__se_sys_munmap mm/mmap.c:2939 [inline]
__x64_sys_munmap+0x5c/0x70 mm/mmap.c:2939
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f5be3c7def7
Code: 00 00 00 48 c7 c2 b0 ff ff ff f7 d8 64 89 02 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 b8 0b 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f5be4910ea8 EFLAGS: 00000246 ORIG_RAX: 000000000000000b
RAX: ffffffffffffffda RBX: 0000000001000000 RCX: 00007f5be3c7def7
RDX: 0000000000000000 RSI: 0000000008400000 RDI: 00007f5bda3f7000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000005598
R10: 0000000000000002 R11: 0000000000000246 R12: 0000000000000006
R13: 00007f5be4910f80 R14: 00007f5be4910f40 R15: 00007f5bda3f7000
</TASK>

Allocated by task 4427:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0x97/0xb0 mm/kasan/common.c:383
kmalloc include/linux/slab.h:556 [inline]
kzalloc include/linux/slab.h:692 [inline]
xpad_probe+0x3be/0x1b10 drivers/input/joystick/xpad.c:1965
usb_probe_interface+0x5c0/0xaf0 drivers/usb/core/driver.c:396
really_probe+0x2ab/0xcb0 drivers/base/dd.c:639
__driver_probe_device+0x1a2/0x3d0 drivers/base/dd.c:785
driver_probe_device+0x50/0x420 drivers/base/dd.c:815
__device_attach_driver+0x2cf/0x510 drivers/base/dd.c:943
bus_for_each_drv+0x183/0x200 drivers/base/bus.c:427
__device_attach+0x359/0x570 drivers/base/dd.c:1015
bus_probe_device+0xba/0x1e0 drivers/base/bus.c:487
device_add+0xb48/0xfd0 drivers/base/core.c:3671
usb_set_configuration+0x19dd/0x2020 drivers/usb/core/message.c:2165
usb_generic_driver_probe+0x84/0x140 drivers/usb/core/generic.c:238
usb_probe_device+0x130/0x260 drivers/usb/core/driver.c:293
really_probe+0x2ab/0xcb0 drivers/base/dd.c:639
__driver_probe_device+0x1a2/0x3d0 drivers/base/dd.c:785
driver_probe_device+0x50/0x420 drivers/base/dd.c:815
__device_attach_driver+0x2cf/0x510 drivers/base/dd.c:943
bus_for_each_drv+0x183/0x200 drivers/base/bus.c:427
__device_attach+0x359/0x570 drivers/base/dd.c:1015
bus_probe_device+0xba/0x1e0 drivers/base/bus.c:487
device_add+0xb48/0xfd0 drivers/base/core.c:3671
usb_new_device+0xbdd/0x18f0 drivers/usb/core/hub.c:2614
hub_port_connect drivers/usb/core/hub.c:5465 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5605 [inline]
port_event drivers/usb/core/hub.c:5761 [inline]
hub_event+0x2efe/0x5730 drivers/usb/core/hub.c:5843
process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
worker_thread+0xa47/0x1200 kernel/workqueue.c:2439
kthread+0x28d/0x320 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:307

Freed by task 16306:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:516
____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
kasan_slab_free include/linux/kasan.h:177 [inline]
slab_free_hook mm/slub.c:1724 [inline]
slab_free_freelist_hook mm/slub.c:1750 [inline]
slab_free mm/slub.c:3661 [inline]
__kmem_cache_free+0x25c/0x3c0 mm/slub.c:3674
xpad_disconnect+0x355/0x480 drivers/input/joystick/xpad.c:2146
usb_unbind_interface+0x1cd/0x840 drivers/usb/core/driver.c:458
device_remove drivers/base/dd.c:550 [inline]
__device_release_driver drivers/base/dd.c:1260 [inline]
device_release_driver_internal+0x59e/0x880 drivers/base/dd.c:1286
bus_remove_device+0x2e5/0x400 drivers/base/bus.c:529
device_del+0x6e2/0xbd0 drivers/base/core.c:3859
usb_disable_device+0x3b8/0x840 drivers/usb/core/message.c:1414
usb_disconnect+0x33c/0x8c0 drivers/usb/core/hub.c:2269
hub_port_connect drivers/usb/core/hub.c:5309 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5605 [inline]
port_event drivers/usb/core/hub.c:5761 [inline]
hub_event+0x1f78/0x5730 drivers/usb/core/hub.c:5843
process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
worker_thread+0xa47/0x1200 kernel/workqueue.c:2439
kthread+0x28d/0x320 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:307

Last potentially related work creation:
kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
__kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:486
call_rcu+0x163/0xa10 kernel/rcu/tree.c:2844
rhashtable_rehash_table lib/rhashtable.c:345 [inline]
rht_deferred_worker+0x1c4d/0x21e0 lib/rhashtable.c:429
process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
worker_thread+0xa47/0x1200 kernel/workqueue.c:2439
kthread+0x28d/0x320 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:307

Second to last potentially related work creation:
kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
__kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:486
call_rcu+0x163/0xa10 kernel/rcu/tree.c:2844
qdisc_put net/sched/sch_generic.c:1090 [inline]
dev_shutdown+0x359/0x440 net/sched/sch_generic.c:1478
unregister_netdevice_many+0xaae/0x17a0 net/core/dev.c:10872
default_device_exit_batch+0x956/0x9d0 net/core/dev.c:11394
ops_exit_list net/core/net_namespace.c:174 [inline]
cleanup_net+0x763/0xb60 net/core/net_namespace.c:601
process_one_work+0x8a9/0x11d0 kernel/workqueue.c:2292
worker_thread+0xa47/0x1200 kernel/workqueue.c:2439
kthread+0x28d/0x320 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:307

The buggy address belongs to the object at ffff888021668000
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 145 bytes inside of
1024-byte region [ffff888021668000, ffff888021668400)

The buggy address belongs to the physical page:
page:ffffea0000859a00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x21668
head:ffffea0000859a00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff80000010200(slab|head|node=0|zone=1|lastcpupid=0xfff)
raw: 00fff80000010200 dead000000000100 dead000000000122 ffff888012441dc0
raw: 0000000000000000 0000000000100010 00000001ffffffff 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 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 3320, tgid 3320 (dhcpcd-run-hook), ts 42918737698, free_ts 42899600086
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x18d/0x1b0 mm/page_alloc.c:2513
prep_new_page mm/page_alloc.c:2520 [inline]
get_page_from_freelist+0x31a1/0x3320 mm/page_alloc.c:4279
__alloc_pages+0x28d/0x770 mm/page_alloc.c:5547
alloc_slab_page+0x6a/0x150 mm/slub.c:1794
allocate_slab mm/slub.c:1939 [inline]
new_slab+0x84/0x2d0 mm/slub.c:1992
___slab_alloc+0xc20/0x1270 mm/slub.c:3180
__slab_alloc mm/slub.c:3279 [inline]
slab_alloc_node mm/slub.c:3364 [inline]
__kmem_cache_alloc_node+0x19f/0x260 mm/slub.c:3437
__do_kmalloc_node mm/slab_common.c:954 [inline]
__kmalloc+0xa1/0x230 mm/slab_common.c:968
kmalloc include/linux/slab.h:561 [inline]
load_elf_phdrs fs/binfmt_elf.c:481 [inline]
load_elf_binary+0x2ec/0x2750 fs/binfmt_elf.c:861
search_binary_handler fs/exec.c:1737 [inline]
exec_binprm fs/exec.c:1778 [inline]
bprm_execve+0x96a/0x18a0 fs/exec.c:1847
do_execveat_common+0x580/0x720 fs/exec.c:1952
do_execve fs/exec.c:2026 [inline]
__do_sys_execve fs/exec.c:2102 [inline]
__se_sys_execve fs/exec.c:2097 [inline]
__x64_sys_execve+0x8e/0xa0 fs/exec.c:2097
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1440 [inline]
free_pcp_prepare mm/page_alloc.c:1490 [inline]
free_unref_page_prepare+0xf63/0x1120 mm/page_alloc.c:3358
free_unref_page+0x33/0x3e0 mm/page_alloc.c:3453
free_slab mm/slub.c:2031 [inline]
discard_slab mm/slub.c:2037 [inline]
__unfreeze_partials+0x1b7/0x210 mm/slub.c:2586
put_cpu_partial+0x17b/0x250 mm/slub.c:2662
qlink_free mm/kasan/quarantine.c:168 [inline]
qlist_free_all+0x76/0xe0 mm/kasan/quarantine.c:187
kasan_quarantine_reduce+0x156/0x170 mm/kasan/quarantine.c:294
__kasan_slab_alloc+0x1f/0x70 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:201 [inline]
slab_post_alloc_hook+0x52/0x3a0 mm/slab.h:737
slab_alloc_node mm/slub.c:3398 [inline]
slab_alloc mm/slub.c:3406 [inline]
__kmem_cache_alloc_lru mm/slub.c:3413 [inline]
kmem_cache_alloc+0x10c/0x2d0 mm/slub.c:3422
getname_flags+0xb8/0x4f0 fs/namei.c:139
vfs_fstatat fs/stat.c:266 [inline]
__do_sys_newfstatat fs/stat.c:437 [inline]
__se_sys_newfstatat fs/stat.c:431 [inline]
__x64_sys_newfstatat+0x130/0x1e0 fs/stat.c:431
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:81
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
ffff888021667f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff888021668000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888021668080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888021668100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888021668180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
----------------
Code disassembly (best guess):
0: 8b 0d 64 e4 77 7e mov 0x7e77e464(%rip),%ecx # 0x7e77e46a
6: 65 8b 05 65 e4 77 7e mov %gs:0x7e77e465(%rip),%eax # 0x7e77e472
d: a9 00 01 ff 00 test $0xff0100,%eax
12: 74 10 je 0x24
14: a9 00 01 00 00 test $0x100,%eax
19: 74 57 je 0x72
1b: 83 b9 1c 16 00 00 00 cmpl $0x0,0x161c(%rcx)
22: 74 4e je 0x72
24: 8b 81 f8 15 00 00 mov 0x15f8(%rcx),%eax
* 2a: 83 f8 03 cmp $0x3,%eax <-- trapping instruction
2d: 75 43 jne 0x72
2f: 48 8b 91 00 16 00 00 mov 0x1600(%rcx),%rdx
36: 44 8b 89 fc 15 00 00 mov 0x15fc(%rcx),%r9d
3d: 49 rex.WB
3e: c1 .byte 0xc1
3f: e1 .byte 0xe1


---
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 syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup
Reply all
Reply to author
Forward
0 new messages