In the Linux kernel, the following vulnerability has been resolved:
net: caif: Fix use-after-free in cfusbldevicenotify()
syzbot reported use-after-free in cfusbldevicenotify() [1]. This causes a stack trace like below:
BUG: KASAN: use-after-free in cfusbldevicenotify+0x7c9/0x870 net/caif/caif_usb.c:138 Read of size 8 at addr ffff88807ac4e6f0 by task kworker/u4:6/1214
CPU: 0 PID: 1214 Comm: kworker/u4:6 Not tainted 5.19.0-rc3-syzkaller-00146-g92f20ff72066 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: netns cleanupnet Call Trace: <TASK> _dumpstack lib/dumpstack.c:88 [inline] dumpstacklvl+0xcd/0x134 lib/dumpstack.c:106 printaddressdescription.constprop.0.cold+0xeb/0x467 mm/kasan/report.c:313 printreport mm/kasan/report.c:429 [inline] kasanreport.cold+0xf4/0x1c6 mm/kasan/report.c:491 cfusbldevicenotify+0x7c9/0x870 net/caif/caifusb.c:138 notifiercallchain+0xb5/0x200 kernel/notifier.c:87 callnetdevicenotifiersinfo+0xb5/0x130 net/core/dev.c:1945 callnetdevicenotifiersextack net/core/dev.c:1983 [inline] callnetdevicenotifiers net/core/dev.c:1997 [inline] netdevwaitallrefsany net/core/dev.c:10227 [inline] netdevruntodo+0xbc0/0x10f0 net/core/dev.c:10341 defaultdeviceexitbatch+0x44e/0x590 net/core/dev.c:11334 opsexitlist+0x125/0x170 net/core/netnamespace.c:167 cleanupnet+0x4ea/0xb00 net/core/netnamespace.c:594 processonework+0x996/0x1610 kernel/workqueue.c:2289 workerthread+0x665/0x1080 kernel/workqueue.c:2436 kthread+0x2e9/0x3a0 kernel/kthread.c:376 retfromfork+0x1f/0x30 arch/x86/entry/entry_64.S:302 </TASK>
When unregistering a net device, unregisternetdevicemanynotify() sets the device's regstate to NETREGUNREGISTERING, calls notifiers with NETDEVUNREGISTER, and adds the device to the todo list.
Later on, devices in the todo list are processed by netdevruntodo(). netdevruntodo() waits devices' reference count become 1 while rebdoadcasting NETDEV_UNREGISTER notification.
When cfusbldevicenotify() is called with NETDEVUNREGISTER multiple times, the parent device might be freed. This could cause UAF. Processing NETDEVUNREGISTER multiple times also causes inbalance of reference count for the module.
This patch fixes the issue by accepting only first NETDEV_UNREGISTER notification.