[v5.15] KASAN: use-after-free Read in __usb_hcd_giveback_urb

0 views
Skip to first unread message

syzbot

unread,
Nov 10, 2023, 9:11:24 PM11/10/23
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 80529b4968a8 Linux 5.15.138
git tree: linux-5.15.y
console output: https://syzkaller.appspot.com/x/log.txt?x=105258b7680000
kernel config: https://syzkaller.appspot.com/x/.config?x=c431dbb457f792c5
dashboard link: https://syzkaller.appspot.com/bug?extid=304797cf4c8e1d64e174
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/4fd4b10a6041/disk-80529b49.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/60443f81279e/vmlinux-80529b49.xz
kernel image: https://storage.googleapis.com/syzbot-assets/c7f38af1be13/bzImage-80529b49.xz

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

xpad 1-1:179.65: xpad_irq_in - usb_submit_urb failed with result -19
xpad 1-1:179.65: xpad_irq_out - usb_submit_urb failed with result -19
==================================================================
BUG: KASAN: use-after-free in debug_spin_lock_before kernel/locking/spinlock_debug.c:85 [inline]
BUG: KASAN: use-after-free in do_raw_spin_lock+0x290/0x370 kernel/locking/spinlock_debug.c:114
Read of size 4 at addr ffff88807a77a85c by task kworker/u4:22/6109

CPU: 1 PID: 6109 Comm: kworker/u4:22 Not tainted 5.15.138-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Workqueue: netns cleanup_net
Call Trace:
<IRQ>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
print_address_description+0x63/0x3b0 mm/kasan/report.c:248
__kasan_report mm/kasan/report.c:434 [inline]
kasan_report+0x16b/0x1c0 mm/kasan/report.c:451
debug_spin_lock_before kernel/locking/spinlock_debug.c:85 [inline]
do_raw_spin_lock+0x290/0x370 kernel/locking/spinlock_debug.c:114
__raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:117 [inline]
_raw_spin_lock_irqsave+0xdd/0x120 kernel/locking/spinlock.c:162
__wake_up_common_lock kernel/sched/wait.c:137 [inline]
__wake_up+0xf5/0x1c0 kernel/sched/wait.c:157
__usb_hcd_giveback_urb+0x3a8/0x530 drivers/usb/core/hcd.c:1677
dummy_timer+0x8ad/0x3200 drivers/usb/gadget/udc/dummy_hcd.c:1987
call_timer_fn+0x16d/0x560 kernel/time/timer.c:1421
expire_timers kernel/time/timer.c:1466 [inline]
__run_timers+0x67c/0x890 kernel/time/timer.c:1737
run_timer_softirq+0x63/0xf0 kernel/time/timer.c:1750
__do_softirq+0x3b3/0x93a kernel/softirq.c:558
invoke_softirq kernel/softirq.c:432 [inline]
__irq_exit_rcu+0x155/0x240 kernel/softirq.c:637
irq_exit_rcu+0x5/0x20 kernel/softirq.c:649
sysvec_apic_timer_interrupt+0x91/0xb0 arch/x86/kernel/apic/apic.c:1096
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x16/0x20 arch/x86/include/asm/idtentry.h:638
RIP: 0010:lock_acquire+0x252/0x4f0 kernel/locking/lockdep.c:5626
Code: 2b 00 74 08 4c 89 f7 e8 1c 59 67 00 f6 44 24 61 02 0f 85 84 01 00 00 41 f7 c7 00 02 00 00 74 01 fb 48 c7 44 24 40 0e 36 e0 45 <4b> c7 44 25 00 00 00 00 00 43 c7 44 25 09 00 00 00 00 43 c7 44 25
RSP: 0018:ffffc9000496f8e0 EFLAGS: 00000206
RAX: 0000000000000001 RBX: 1ffff9200092df28 RCX: 1ffff9200092dec8
RDX: dffffc0000000000 RSI: ffffffff8a8b1e80 RDI: ffffffff8ad87b40
RBP: ffffc9000496fa40 R08: dffffc0000000000 R09: fffffbfff1f79c21
R10: 0000000000000000 R11: dffffc0000000001 R12: 1ffff9200092df24
R13: dffffc0000000000 R14: ffffc9000496f940 R15: 0000000000000246
rcu_lock_acquire+0x2a/0x30 include/linux/rcupdate.h:269
rcu_read_lock include/linux/rcupdate.h:696 [inline]
inet_twsk_purge+0x11e/0xa20 net/ipv4/inet_timewait_sock.c:268
ops_exit_list net/core/net_namespace.c:174 [inline]
cleanup_net+0x763/0xb60 net/core/net_namespace.c:596
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
</TASK>

Allocated by task 4437:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:434 [inline]
____kasan_kmalloc+0xba/0xf0 mm/kasan/common.c:513
kasan_kmalloc include/linux/kasan.h:264 [inline]
kmem_cache_alloc_trace+0x143/0x290 mm/slub.c:3247
kmalloc include/linux/slab.h:591 [inline]
kzalloc include/linux/slab.h:721 [inline]
xpad_probe+0x3eb/0x1b10 drivers/input/joystick/xpad.c:1780
usb_probe_interface+0x5c0/0xaf0 drivers/usb/core/driver.c:396
really_probe+0x24e/0xb60 drivers/base/dd.c:595
__driver_probe_device+0x1a2/0x3d0 drivers/base/dd.c:755
driver_probe_device+0x50/0x420 drivers/base/dd.c:785
__device_attach_driver+0x2b9/0x500 drivers/base/dd.c:907
bus_for_each_drv+0x183/0x200 drivers/base/bus.c:427
__device_attach+0x359/0x570 drivers/base/dd.c:979
bus_probe_device+0xba/0x1e0 drivers/base/bus.c:487
device_add+0xb48/0xfd0 drivers/base/core.c:3394
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+0x24e/0xb60 drivers/base/dd.c:595
__driver_probe_device+0x1a2/0x3d0 drivers/base/dd.c:755
driver_probe_device+0x50/0x420 drivers/base/dd.c:785
__device_attach_driver+0x2b9/0x500 drivers/base/dd.c:907
bus_for_each_drv+0x183/0x200 drivers/base/bus.c:427
__device_attach+0x359/0x570 drivers/base/dd.c:979
bus_probe_device+0xba/0x1e0 drivers/base/bus.c:487
device_add+0xb48/0xfd0 drivers/base/core.c:3394
usb_new_device+0xc17/0x18d0 drivers/usb/core/hub.c:2576
hub_port_connect drivers/usb/core/hub.c:5437 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5577 [inline]
port_event drivers/usb/core/hub.c:5723 [inline]
hub_event+0x2cdf/0x54c0 drivers/usb/core/hub.c:5805
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298

Freed by task 5233:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track+0x4b/0x80 mm/kasan/common.c:46
kasan_set_free_info+0x1f/0x40 mm/kasan/generic.c:360
____kasan_slab_free+0xd8/0x120 mm/kasan/common.c:366
kasan_slab_free include/linux/kasan.h:230 [inline]
slab_free_hook mm/slub.c:1705 [inline]
slab_free_freelist_hook+0xdd/0x160 mm/slub.c:1731
slab_free mm/slub.c:3499 [inline]
kfree+0xf1/0x270 mm/slub.c:4559
xpad_disconnect+0x355/0x480 drivers/input/joystick/xpad.c:1928
usb_unbind_interface+0x1cd/0x840 drivers/usb/core/driver.c:458
__device_release_driver drivers/base/dd.c:1229 [inline]
device_release_driver_internal+0x50e/0x7f0 drivers/base/dd.c:1262
bus_remove_device+0x2e5/0x400 drivers/base/bus.c:529
device_del+0x6e2/0xbd0 drivers/base/core.c:3582
usb_disable_device+0x3b8/0x840 drivers/usb/core/message.c:1414
usb_disconnect+0x33c/0x8c0 drivers/usb/core/hub.c:2239
hub_port_connect drivers/usb/core/hub.c:5281 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5577 [inline]
port_event drivers/usb/core/hub.c:5723 [inline]
hub_event+0x1d58/0x54c0 drivers/usb/core/hub.c:5805
process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
kthread+0x3f6/0x4f0 kernel/kthread.c:319
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298

The buggy address belongs to the object at ffff88807a77a800
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 92 bytes inside of
1024-byte region [ffff88807a77a800, ffff88807a77ac00)
The buggy address belongs to the page:
page:ffffea0001e9de00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7a778
head:ffffea0001e9de00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff888011c41dc0
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 0xd2a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 3503, ts 127128037269, free_ts 127122342159
prep_new_page mm/page_alloc.c:2426 [inline]
get_page_from_freelist+0x322a/0x33c0 mm/page_alloc.c:4159
__alloc_pages+0x272/0x700 mm/page_alloc.c:5421
alloc_slab_page mm/slub.c:1775 [inline]
allocate_slab mm/slub.c:1912 [inline]
new_slab+0xbb/0x4b0 mm/slub.c:1975
___slab_alloc+0x6f6/0xe10 mm/slub.c:3008
__slab_alloc mm/slub.c:3095 [inline]
slab_alloc_node mm/slub.c:3186 [inline]
__kmalloc_node_track_caller+0x1f6/0x390 mm/slub.c:4958
kmalloc_reserve net/core/skbuff.c:356 [inline]
__alloc_skb+0x12c/0x590 net/core/skbuff.c:427
alloc_skb include/linux/skbuff.h:1167 [inline]
__tcp_send_ack+0x9c/0x630 net/ipv4/tcp_output.c:3975
tcp_recvmsg_locked+0x23b1/0x29b0 net/ipv4/tcp.c:2521
tcp_recvmsg+0x24e/0x7f0 net/ipv4/tcp.c:2551
inet_recvmsg+0x157/0x280 net/ipv4/af_inet.c:856
sock_recvmsg_nosec net/socket.c:964 [inline]
sock_recvmsg net/socket.c:982 [inline]
sock_read_iter+0x353/0x480 net/socket.c:1055
call_read_iter include/linux/fs.h:2097 [inline]
new_sync_read fs/read_write.c:404 [inline]
vfs_read+0xa9f/0xe10 fs/read_write.c:485
ksys_read+0x1a2/0x2c0 fs/read_write.c:623
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x61/0xcb
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1340 [inline]
free_pcp_prepare mm/page_alloc.c:1391 [inline]
free_unref_page_prepare+0xc34/0xcf0 mm/page_alloc.c:3317
free_unref_page+0x95/0x2d0 mm/page_alloc.c:3396
skb_free_frag include/linux/skbuff.h:3024 [inline]
skb_free_head net/core/skbuff.c:653 [inline]
skb_release_data+0x749/0x8a0 net/core/skbuff.c:677
skb_release_all net/core/skbuff.c:742 [inline]
__kfree_skb+0x4c/0x60 net/core/skbuff.c:756
sk_eat_skb include/net/sock.h:2704 [inline]
tcp_recvmsg_locked+0x1629/0x29b0 net/ipv4/tcp.c:2505
tcp_recvmsg+0x24e/0x7f0 net/ipv4/tcp.c:2551
inet_recvmsg+0x157/0x280 net/ipv4/af_inet.c:856
sock_recvmsg_nosec net/socket.c:964 [inline]
sock_recvmsg net/socket.c:982 [inline]
sock_read_iter+0x353/0x480 net/socket.c:1055
call_read_iter include/linux/fs.h:2097 [inline]
new_sync_read fs/read_write.c:404 [inline]
vfs_read+0xa9f/0xe10 fs/read_write.c:485
ksys_read+0x1a2/0x2c0 fs/read_write.c:623
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x61/0xcb

Memory state around the buggy address:
ffff88807a77a700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88807a77a780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88807a77a800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807a77a880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807a77a900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
----------------
Code disassembly (best guess):
0: 2b 00 sub (%rax),%eax
2: 74 08 je 0xc
4: 4c 89 f7 mov %r14,%rdi
7: e8 1c 59 67 00 call 0x675928
c: f6 44 24 61 02 testb $0x2,0x61(%rsp)
11: 0f 85 84 01 00 00 jne 0x19b
17: 41 f7 c7 00 02 00 00 test $0x200,%r15d
1e: 74 01 je 0x21
20: fb sti
21: 48 c7 44 24 40 0e 36 movq $0x45e0360e,0x40(%rsp)
28: e0 45
* 2a: 4b c7 44 25 00 00 00 movq $0x0,0x0(%r13,%r12,1) <-- trapping instruction
31: 00 00
33: 43 c7 44 25 09 00 00 movl $0x0,0x9(%r13,%r12,1)
3a: 00 00
3c: 43 rex.XB
3d: c7 .byte 0xc7
3e: 44 rex.R
3f: 25 .byte 0x25


---
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