[syzbot] KASAN: use-after-free Read in cdc_ncm_tx_fixup

14 views
Skip to first unread message

syzbot

unread,
Dec 13, 2021, 7:20:25 AM12/13/21
to da...@davemloft.net, ku...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, net...@vger.kernel.org, oli...@neukum.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 2a987e65025e Merge tag 'perf-tools-fixes-for-v5.16-2021-12..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=12a848b9b00000
kernel config: https://syzkaller.appspot.com/x/.config?x=5247c9e141823545
dashboard link: https://syzkaller.appspot.com/bug?extid=5ec3d1378e31c88d87f4
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2

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

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

usb 7-1: USB disconnect, device number 2
cdc_ncm 7-1:1.0 usb0: unregister 'cdc_ncm' usb-dummy_hcd.2-1, CDC NCM
==================================================================
BUG: KASAN: use-after-free in __lock_acquire+0x3d86/0x54a0 kernel/locking/lockdep.c:4897
Read of size 8 at addr ffff888018b184f0 by task kworker/2:1/40

CPU: 2 PID: 40 Comm: kworker/2:1 Not tainted 5.16.0-rc4-syzkaller #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
Workqueue: usb_hub_wq hub_event
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description.constprop.0.cold+0x8d/0x2ed mm/kasan/report.c:247
__kasan_report mm/kasan/report.c:433 [inline]
kasan_report.cold+0x83/0xdf mm/kasan/report.c:450
__lock_acquire+0x3d86/0x54a0 kernel/locking/lockdep.c:4897
lock_acquire kernel/locking/lockdep.c:5637 [inline]
lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5602
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x2f/0x40 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:354 [inline]
cdc_ncm_tx_fixup+0x8f/0x120 drivers/net/usb/cdc_ncm.c:1525
usbnet_start_xmit+0x152/0x1f70 drivers/net/usb/usbnet.c:1372
__netdev_start_xmit include/linux/netdevice.h:4994 [inline]
netdev_start_xmit include/linux/netdevice.h:5008 [inline]
xmit_one net/core/dev.c:3590 [inline]
dev_hard_start_xmit+0x1eb/0x920 net/core/dev.c:3606
sch_direct_xmit+0x19f/0xbe0 net/sched/sch_generic.c:342
__dev_xmit_skb net/core/dev.c:3817 [inline]
__dev_queue_xmit+0x149c/0x3650 net/core/dev.c:4194
lapb_data_transmit+0x8f/0xc0 net/lapb/lapb_iface.c:447
lapb_transmit_buffer+0x183/0x390 net/lapb/lapb_out.c:149
lapb_send_control+0x1c7/0x370 net/lapb/lapb_subr.c:251
__lapb_disconnect_request+0x127/0x1a0 net/lapb/lapb_iface.c:326
lapb_device_event+0x292/0x560 net/lapb/lapb_iface.c:492
notifier_call_chain+0xb5/0x200 kernel/notifier.c:83
call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:2002
call_netdevice_notifiers_extack net/core/dev.c:2014 [inline]
call_netdevice_notifiers net/core/dev.c:2028 [inline]
__dev_close_many+0xf1/0x2e0 net/core/dev.c:1548
dev_close_many+0x22c/0x620 net/core/dev.c:1599
dev_close net/core/dev.c:1625 [inline]
dev_close+0x16d/0x210 net/core/dev.c:1619
lapbeth_device_event+0x677/0xc00 drivers/net/wan/lapbether.c:462
notifier_call_chain+0xb5/0x200 kernel/notifier.c:83
call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:2002
call_netdevice_notifiers_extack net/core/dev.c:2014 [inline]
call_netdevice_notifiers net/core/dev.c:2028 [inline]
__dev_close_many+0xf1/0x2e0 net/core/dev.c:1548
dev_close_many+0x22c/0x620 net/core/dev.c:1599
unregister_netdevice_many+0x3ff/0x1790 net/core/dev.c:11057
unregister_netdevice_queue+0x2dd/0x3c0 net/core/dev.c:11014
unregister_netdevice include/linux/netdevice.h:2989 [inline]
unregister_netdev+0x18/0x20 net/core/dev.c:11139
usbnet_disconnect+0x139/0x270 drivers/net/usb/usbnet.c:1623
usb_unbind_interface+0x1d8/0x8e0 drivers/usb/core/driver.c:458
__device_release_driver+0x5d7/0x700 drivers/base/dd.c:1205
device_release_driver_internal drivers/base/dd.c:1236 [inline]
device_release_driver+0x26/0x40 drivers/base/dd.c:1259
bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
device_del+0x502/0xd60 drivers/base/core.c:3581
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:5197 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5497 [inline]
port_event drivers/usb/core/hub.c:5643 [inline]
hub_event+0x1c9c/0x4460 drivers/usb/core/hub.c:5725
process_one_work+0x9b2/0x1690 kernel/workqueue.c:2298
worker_thread+0x658/0x11f0 kernel/workqueue.c:2445
kthread+0x405/0x4f0 kernel/kthread.c:327
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
</TASK>

Allocated by task 40:
kasan_save_stack+0x1e/0x50 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+0xa6/0xd0 mm/kasan/common.c:522
kasan_kmalloc include/linux/kasan.h:269 [inline]
kmem_cache_alloc_trace+0x1ea/0x4a0 mm/slab.c:3575
kmalloc include/linux/slab.h:590 [inline]
kzalloc include/linux/slab.h:724 [inline]
cdc_ncm_bind_common+0xb8/0x2df0 drivers/net/usb/cdc_ncm.c:824
cdc_ncm_bind+0x7c/0x1c0 drivers/net/usb/cdc_ncm.c:1067
usbnet_probe+0xb21/0x25b0 drivers/net/usb/usbnet.c:1747
usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:517 [inline]
really_probe+0x245/0xcc0 drivers/base/dd.c:596
__driver_probe_device+0x338/0x4d0 drivers/base/dd.c:751
driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:781
__device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:898
bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
__device_attach+0x228/0x4a0 drivers/base/dd.c:969
bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
device_add+0xc17/0x1ee0 drivers/base/core.c:3394
usb_set_configuration+0x101e/0x1900 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+0x245/0xcc0 drivers/base/dd.c:596
__driver_probe_device+0x338/0x4d0 drivers/base/dd.c:751
driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:781
__device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:898
bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
__device_attach+0x228/0x4a0 drivers/base/dd.c:969
bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
device_add+0xc17/0x1ee0 drivers/base/core.c:3394
usb_new_device.cold+0x63f/0x108e drivers/usb/core/hub.c:2563
hub_port_connect drivers/usb/core/hub.c:5353 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5497 [inline]
port_event drivers/usb/core/hub.c:5643 [inline]
hub_event+0x23e5/0x4460 drivers/usb/core/hub.c:5725
process_one_work+0x9b2/0x1690 kernel/workqueue.c:2298
worker_thread+0x658/0x11f0 kernel/workqueue.c:2445
kthread+0x405/0x4f0 kernel/kthread.c:327
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Freed by task 40:
kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
kasan_set_track+0x21/0x30 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free mm/kasan/common.c:328 [inline]
__kasan_slab_free+0xd1/0x110 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:235 [inline]
__cache_free mm/slab.c:3445 [inline]
kfree+0x10d/0x2c0 mm/slab.c:3802
cdc_ncm_free+0x145/0x1a0 drivers/net/usb/cdc_ncm.c:784
cdc_ncm_unbind+0x1a7/0x340 drivers/net/usb/cdc_ncm.c:1019
usbnet_disconnect+0x103/0x270 drivers/net/usb/usbnet.c:1620
usb_unbind_interface+0x1d8/0x8e0 drivers/usb/core/driver.c:458
__device_release_driver+0x5d7/0x700 drivers/base/dd.c:1205
device_release_driver_internal drivers/base/dd.c:1236 [inline]
device_release_driver+0x26/0x40 drivers/base/dd.c:1259
bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
device_del+0x502/0xd60 drivers/base/core.c:3581
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:5197 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5497 [inline]
port_event drivers/usb/core/hub.c:5643 [inline]
hub_event+0x1c9c/0x4460 drivers/usb/core/hub.c:5725
process_one_work+0x9b2/0x1690 kernel/workqueue.c:2298
worker_thread+0x658/0x11f0 kernel/workqueue.c:2445
kthread+0x405/0x4f0 kernel/kthread.c:327
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff888018b18400
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 240 bytes inside of
512-byte region [ffff888018b18400, ffff888018b18600)
The buggy address belongs to the page:
page:ffffea000062c600 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888018b18c00 pfn:0x18b18
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea00006274c8 ffffea000063dd88 ffff888010c40600
raw: ffff888018b18c00 ffff888018b18000 0000000100000003 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x2420c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_THISNODE), pid 545, ts 26238686038, free_ts 26238573279
prep_new_page mm/page_alloc.c:2418 [inline]
get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4149
__alloc_pages+0x1b2/0x500 mm/page_alloc.c:5369
__alloc_pages_node include/linux/gfp.h:570 [inline]
kmem_getpages mm/slab.c:1377 [inline]
cache_grow_begin+0x75/0x470 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+0x380/0x4a0 mm/slab.c:3573
kmalloc include/linux/slab.h:590 [inline]
kzalloc include/linux/slab.h:724 [inline]
alloc_bprm+0x51/0x8f0 fs/exec.c:1503
kernel_execve+0x55/0x460 fs/exec.c:1943
call_usermodehelper_exec_async+0x2e3/0x580 kernel/umh.c:112
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1338 [inline]
free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1389
free_unref_page_prepare mm/page_alloc.c:3309 [inline]
free_unref_page+0x19/0x690 mm/page_alloc.c:3388
rcu_do_batch kernel/rcu/tree.c:2506 [inline]
rcu_core+0x7ab/0x1470 kernel/rcu/tree.c:2741
__do_softirq+0x29b/0x9c2 kernel/softirq.c:558
run_ksoftirqd kernel/softirq.c:921 [inline]
run_ksoftirqd+0x2d/0x60 kernel/softirq.c:913
smpboot_thread_fn+0x645/0x9c0 kernel/smpboot.c:164
kthread+0x405/0x4f0 kernel/kthread.c:327
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Memory state around the buggy address:
ffff888018b18380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888018b18400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888018b18480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888018b18500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888018b18580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


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

Hillf Danton

unread,
Dec 14, 2021, 6:06:32 AM12/14/21
to syzbot, linux-...@vger.kernel.org, linu...@vger.kernel.org, net...@vger.kernel.org, oli...@neukum.org, syzkall...@googlegroups.com
On Mon, 13 Dec 2021 04:20:24 -0800
Fix uaf by marking ctx goes home in the unbind callback.

+++ x/drivers/net/usb/usbnet.c
@@ -995,6 +995,14 @@ void cdc_ncm_unbind(struct usbnet *dev,
if (ctx == NULL)
return; /* no setup */

+ /*
+ * info cdc_ncm_tx_fixup() ctx gone
+ *
+ * see the unbind() and unregister_netdev() sequences in
+ * usbnet_disconnect()
+ */
+ dev->data[0] = 0;
+
atomic_set(&ctx->stop, 1);

hrtimer_cancel(&ctx->tx_timer);

Hillf Danton

unread,
Dec 14, 2021, 6:18:47 AM12/14/21
to syzbot, linux-...@vger.kernel.org, linu...@vger.kernel.org, net...@vger.kernel.org, oli...@neukum.org, syzkall...@googlegroups.com
On Mon, 13 Dec 2021 04:20:24 -0800
Fix uaf by marking ctx goes home in the unbind callback.
Spin with typo fixed.

+++ x/drivers/net/usb/cdc_ncm.c

syzbot

unread,
Mar 8, 2022, 2:01:25 AM3/8/22
to da...@davemloft.net, fghee...@gmail.com, hda...@sina.com, ku...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, net...@vger.kernel.org, oli...@neukum.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: ea4424be1688 Merge tag 'mtd/fixes-for-5.17-rc8' of git://g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=12c2811a700000
kernel config: https://syzkaller.appspot.com/x/.config?x=442f8ac61e60a75e
dashboard link: https://syzkaller.appspot.com/bug?extid=5ec3d1378e31c88d87f4
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=13c97bbe700000

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

usb 1-1: USB disconnect, device number 2
cdc_ncm 1-1:1.0 usb0: unregister 'cdc_ncm' usb-dummy_hcd.0-1, CDC NCM
==================================================================
BUG: KASAN: use-after-free in __lock_acquire+0x3f2f/0x56c0 kernel/locking/lockdep.c:4897
Read of size 8 at addr ffff888018d2c8f0 by task kworker/1:4/3612

CPU: 1 PID: 3612 Comm: kworker/1:4 Not tainted 5.17.0-rc7-syzkaller-00020-gea4424be1688 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: usb_hub_wq hub_event
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description.constprop.0.cold+0x8d/0x336 mm/kasan/report.c:255
__kasan_report mm/kasan/report.c:442 [inline]
kasan_report.cold+0x83/0xdf mm/kasan/report.c:459
__lock_acquire+0x3f2f/0x56c0 kernel/locking/lockdep.c:4897
lock_acquire kernel/locking/lockdep.c:5639 [inline]
lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5604
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x2f/0x40 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:354 [inline]
cdc_ncm_tx_fixup+0x8f/0x120 drivers/net/usb/cdc_ncm.c:1527
usbnet_start_xmit+0x152/0x1f70 drivers/net/usb/usbnet.c:1372
__netdev_start_xmit include/linux/netdevice.h:4683 [inline]
netdev_start_xmit include/linux/netdevice.h:4697 [inline]
xmit_one net/core/dev.c:3473 [inline]
dev_hard_start_xmit+0x1eb/0x920 net/core/dev.c:3489
sch_direct_xmit+0x19f/0xbe0 net/sched/sch_generic.c:342
__dev_xmit_skb net/core/dev.c:3700 [inline]
__dev_queue_xmit+0x148f/0x37b0 net/core/dev.c:4081
lapb_data_transmit+0x8f/0xc0 net/lapb/lapb_iface.c:447
lapb_transmit_buffer+0x183/0x390 net/lapb/lapb_out.c:149
lapb_send_control+0x1c7/0x370 net/lapb/lapb_subr.c:251
__lapb_disconnect_request+0x127/0x1a0 net/lapb/lapb_iface.c:326
lapb_device_event+0x292/0x560 net/lapb/lapb_iface.c:492
notifier_call_chain+0xb5/0x200 kernel/notifier.c:84
call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:1919
call_netdevice_notifiers_extack net/core/dev.c:1931 [inline]
call_netdevice_notifiers net/core/dev.c:1945 [inline]
__dev_close_many+0xf1/0x2e0 net/core/dev.c:1465
dev_close_many+0x22c/0x620 net/core/dev.c:1516
dev_close net/core/dev.c:1542 [inline]
dev_close+0x16d/0x210 net/core/dev.c:1536
lapbeth_device_event+0x677/0xc00 drivers/net/wan/lapbether.c:462
notifier_call_chain+0xb5/0x200 kernel/notifier.c:84
call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:1919
call_netdevice_notifiers_extack net/core/dev.c:1931 [inline]
call_netdevice_notifiers net/core/dev.c:1945 [inline]
__dev_close_many+0xf1/0x2e0 net/core/dev.c:1465
dev_close_many+0x22c/0x620 net/core/dev.c:1516
unregister_netdevice_many+0x3ff/0x18d0 net/core/dev.c:10392
unregister_netdevice_queue net/core/dev.c:10349 [inline]
unregister_netdevice_queue+0x2dd/0x3c0 net/core/dev.c:10339
unregister_netdevice include/linux/netdevice.h:2902 [inline]
unregister_netdev+0x18/0x20 net/core/dev.c:10474
usbnet_disconnect+0x139/0x270 drivers/net/usb/usbnet.c:1623
usb_unbind_interface+0x1d8/0x8e0 drivers/usb/core/driver.c:458
__device_release_driver+0x627/0x760 drivers/base/dd.c:1209
device_release_driver_internal drivers/base/dd.c:1242 [inline]
device_release_driver+0x26/0x40 drivers/base/dd.c:1265
bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
device_del+0x4f3/0xc80 drivers/base/core.c:3592
usb_disable_device+0x35b/0x7b0 drivers/usb/core/message.c:1419
usb_disconnect.cold+0x27a/0x78e drivers/usb/core/hub.c:2228
hub_port_connect drivers/usb/core/hub.c:5202 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5502 [inline]
port_event drivers/usb/core/hub.c:5660 [inline]
hub_event+0x1e39/0x44d0 drivers/usb/core/hub.c:5742
process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
worker_thread+0x657/0x1110 kernel/workqueue.c:2454
kthread+0x2e9/0x3a0 kernel/kthread.c:377
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
</TASK>

Allocated by task 3596:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:45 [inline]
set_alloc_info mm/kasan/common.c:436 [inline]
____kasan_kmalloc mm/kasan/common.c:515 [inline]
____kasan_kmalloc mm/kasan/common.c:474 [inline]
__kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:524
kmalloc include/linux/slab.h:581 [inline]
kzalloc include/linux/slab.h:714 [inline]
cdc_ncm_bind_common+0xb8/0x2df0 drivers/net/usb/cdc_ncm.c:826
cdc_ncm_bind+0x7c/0x1c0 drivers/net/usb/cdc_ncm.c:1069
usbnet_probe+0xaf8/0x2580 drivers/net/usb/usbnet.c:1747
usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:517 [inline]
really_probe+0x245/0xcc0 drivers/base/dd.c:596
__driver_probe_device+0x338/0x4d0 drivers/base/dd.c:755
driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:785
__device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:902
bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
__device_attach+0x228/0x4a0 drivers/base/dd.c:973
bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
device_add+0xb83/0x1e20 drivers/base/core.c:3405
usb_set_configuration+0x101e/0x1900 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+0x245/0xcc0 drivers/base/dd.c:596
__driver_probe_device+0x338/0x4d0 drivers/base/dd.c:755
driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:785
__device_attach_driver+0x20b/0x2f0 drivers/base/dd.c:902
bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
__device_attach+0x228/0x4a0 drivers/base/dd.c:973
bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
device_add+0xb83/0x1e20 drivers/base/core.c:3405
usb_new_device.cold+0x63f/0x108e drivers/usb/core/hub.c:2566
hub_port_connect drivers/usb/core/hub.c:5358 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5502 [inline]
port_event drivers/usb/core/hub.c:5660 [inline]
hub_event+0x2585/0x44d0 drivers/usb/core/hub.c:5742
process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
worker_thread+0x657/0x1110 kernel/workqueue.c:2454
kthread+0x2e9/0x3a0 kernel/kthread.c:377
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

Freed by task 3612:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
kasan_set_track+0x21/0x30 mm/kasan/common.c:45
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free+0x126/0x160 mm/kasan/common.c:328
kasan_slab_free include/linux/kasan.h:236 [inline]
slab_free_hook mm/slub.c:1728 [inline]
slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1754
slab_free mm/slub.c:3509 [inline]
kfree+0xd0/0x390 mm/slub.c:4562
cdc_ncm_free+0x145/0x1a0 drivers/net/usb/cdc_ncm.c:786
cdc_ncm_unbind+0x1a7/0x340 drivers/net/usb/cdc_ncm.c:1021
usbnet_disconnect+0x103/0x270 drivers/net/usb/usbnet.c:1620
usb_unbind_interface+0x1d8/0x8e0 drivers/usb/core/driver.c:458
__device_release_driver+0x627/0x760 drivers/base/dd.c:1209
device_release_driver_internal drivers/base/dd.c:1242 [inline]
device_release_driver+0x26/0x40 drivers/base/dd.c:1265
bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:529
device_del+0x4f3/0xc80 drivers/base/core.c:3592
usb_disable_device+0x35b/0x7b0 drivers/usb/core/message.c:1419
usb_disconnect.cold+0x27a/0x78e drivers/usb/core/hub.c:2228
hub_port_connect drivers/usb/core/hub.c:5202 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5502 [inline]
port_event drivers/usb/core/hub.c:5660 [inline]
hub_event+0x1e39/0x44d0 drivers/usb/core/hub.c:5742
process_one_work+0x9ac/0x1650 kernel/workqueue.c:2307
worker_thread+0x657/0x1110 kernel/workqueue.c:2454
kthread+0x2e9/0x3a0 kernel/kthread.c:377
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff888018d2c800
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 240 bytes inside of
512-byte region [ffff888018d2c800, ffff888018d2ca00)
The buggy address belongs to the page:
page:ffffea0000634b00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x18d2c
head:ffffea0000634b00 order:2 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffffea0000721d00 dead000000000002 ffff888010c41c80
raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 472, ts 7097294333, free_ts 0
prep_new_page mm/page_alloc.c:2434 [inline]
get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4165
__alloc_pages+0x1b2/0x500 mm/page_alloc.c:5389
alloc_pages+0x1aa/0x310 mm/mempolicy.c:2271
alloc_slab_page mm/slub.c:1799 [inline]
allocate_slab+0x27f/0x3c0 mm/slub.c:1944
new_slab mm/slub.c:2004 [inline]
___slab_alloc+0xbe1/0x12b0 mm/slub.c:3018
__slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3105
slab_alloc_node mm/slub.c:3196 [inline]
slab_alloc mm/slub.c:3238 [inline]
kmem_cache_alloc_trace+0x2f8/0x3d0 mm/slub.c:3255
kmalloc include/linux/slab.h:581 [inline]
kzalloc include/linux/slab.h:714 [inline]
alloc_bprm+0x51/0x8f0 fs/exec.c:1507
kernel_execve+0x55/0x460 fs/exec.c:1947
call_usermodehelper_exec_async+0x2e3/0x580 kernel/umh.c:112
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
page_owner free stack trace missing

Memory state around the buggy address:
ffff888018d2c780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888018d2c800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888018d2c880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888018d2c900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888018d2c980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Hillf Danton

unread,
Mar 8, 2022, 10:08:54 AM3/8/22
to syzbot, linux-...@vger.kernel.org, linu...@vger.kernel.org, net...@vger.kernel.org, syzkall...@googlegroups.com
On Mon, 07 Mar 2022 23:01:24 -0800
To fix uaf, deattach ctx from dev on unbind.

Hillf

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ ea4424be1688

--- x/drivers/net/usb/cdc_ncm.c
+++ y/drivers/net/usb/cdc_ncm.c
@@ -1017,6 +1017,7 @@ void cdc_ncm_unbind(struct usbnet *dev,
ctx->control = NULL;
}

+ dev->data[0] = 0;
usb_set_intfdata(intf, NULL);
cdc_ncm_free(ctx);
}
--

syzbot

unread,
Mar 8, 2022, 10:20:10 AM3/8/22
to hda...@sina.com, linux-...@vger.kernel.org, linu...@vger.kernel.org, net...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+5ec3d1...@syzkaller.appspotmail.com

Tested on:

commit: ea4424be Merge tag 'mtd/fixes-for-5.17-rc8' of git://g..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
kernel config: https://syzkaller.appspot.com/x/.config?x=442f8ac61e60a75e
dashboard link: https://syzkaller.appspot.com/bug?extid=5ec3d1378e31c88d87f4
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=129f209a700000

Note: testing is done by a robot and is best-effort only.

syzbot

unread,
Jun 9, 2022, 8:23:14 AM6/9/22
to da...@davemloft.net, fghee...@gmail.com, hda...@sina.com, ku...@kernel.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, lu...@wunner.de, net...@vger.kernel.org, oli...@neukum.org, one...@suse.com, syzkall...@googlegroups.com
syzbot suspects this issue was fixed by commit:

commit d1408f6b4dd78fb1b9e26bcf64477984e5f85409
Author: Lukas Wunner <lu...@wunner.de>
Date: Thu May 12 08:42:01 2022 +0000

usbnet: Run unregister_netdev() before unbind() again

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=122a4b57f00000
start commit: 330f4c53d3c2 ARM: fix build error when BPF_SYSCALL is disa..
git tree: upstream
kernel config: https://syzkaller.appspot.com/x/.config?x=aba0ab2928a512c2
dashboard link: https://syzkaller.appspot.com/bug?extid=5ec3d1378e31c88d87f4
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=135ca155700000

If the result looks correct, please mark the issue as fixed by replying with:

#syz fix: usbnet: Run unregister_netdev() before unbind() again

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

syzbot

unread,
Oct 2, 2022, 2:58:29 AM10/2/22
to syzkall...@googlegroups.com
Auto-closing this bug as obsolete.
No recent activity, existing reproducers are no longer triggering the issue.
Reply all
Reply to author
Forward
0 new messages