Re: WARNING in r871xu_dev_remove
Hello, syzbot has tested the proposed patch but the reproducer still triggered crash: KASAN: use-after-free Read in device_release_driver_internal == BUG: KASAN: use-after-free in __mutex_lock_common kernel/locking/mutex.c:912 [inline] BUG: KASAN: use-after-free in __mutex_lock+0xf23/0x1360 kernel/locking/mutex.c:1077 Read of size 8 at addr 8881d644bd78 by task kworker/0:4/2855 CPU: 0 PID: 2855 Comm: kworker/0:4 Not tainted 5.3.0-rc5+ #1 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: usb_hub_wq hub_event Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xca/0x13e lib/dump_stack.c:113 print_address_description+0x6a/0x32c mm/kasan/report.c:351 __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:482 kasan_report+0xe/0x12 mm/kasan/common.c:612 __mutex_lock_common kernel/locking/mutex.c:912 [inline] __mutex_lock+0xf23/0x1360 kernel/locking/mutex.c:1077 device_release_driver_internal+0x23/0x500 drivers/base/dd.c:1162 bus_remove_device+0x2dc/0x4a0 drivers/base/bus.c:556 device_del+0x420/0xb10 drivers/base/core.c:2339 usb_disconnect+0x4c3/0x8d0 drivers/usb/core/hub.c:2225 hub_port_connect drivers/usb/core/hub.c:4949 [inline] hub_port_connect_change drivers/usb/core/hub.c:5213 [inline] port_event drivers/usb/core/hub.c:5359 [inline] hub_event+0x1454/0x3640 drivers/usb/core/hub.c:5441 process_one_work+0x92b/0x1530 kernel/workqueue.c:2269 worker_thread+0x96/0xe20 kernel/workqueue.c:2415 kthread+0x318/0x420 kernel/kthread.c:255 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352 Allocated by task 12: save_stack+0x1b/0x80 mm/kasan/common.c:69 set_track mm/kasan/common.c:77 [inline] __kasan_kmalloc mm/kasan/common.c:487 [inline] __kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:460 kmalloc include/linux/slab.h:552 [inline] kzalloc include/linux/slab.h:748 [inline] usb_alloc_dev+0x51/0xf95 drivers/usb/core/usb.c:583 hub_port_connect drivers/usb/core/hub.c:5004 [inline] hub_port_connect_change drivers/usb/core/hub.c:5213 [inline] port_event drivers/usb/core/hub.c:5359 [inline] hub_event+0x15c0/0x3640 drivers/usb/core/hub.c:5441 process_one_work+0x92b/0x1530 kernel/workqueue.c:2269 worker_thread+0x96/0xe20 kernel/workqueue.c:2415 kthread+0x318/0x420 kernel/kthread.c:255 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352 Freed by task 2855: save_stack+0x1b/0x80 mm/kasan/common.c:69 set_track mm/kasan/common.c:77 [inline] __kasan_slab_free+0x130/0x180 mm/kasan/common.c:449 slab_free_hook mm/slub.c:1423 [inline] slab_free_freelist_hook mm/slub.c:1474 [inline] slab_free mm/slub.c:3016 [inline] kfree+0xe4/0x2f0 mm/slub.c:3957 device_release+0x71/0x200 drivers/base/core.c:1064 kobject_cleanup lib/kobject.c:693 [inline] kobject_release lib/kobject.c:722 [inline] kref_put include/linux/kref.h:65 [inline] kobject_put+0x171/0x280 lib/kobject.c:739 put_device+0x1b/0x30 drivers/base/core.c:2264 klist_put+0xce/0x170 lib/klist.c:221 bus_remove_device+0x3a4/0x4a0 drivers/base/bus.c:552 device_del+0x420/0xb10 drivers/base/core.c:2339 usb_disconnect+0x4c3/0x8d0 drivers/usb/core/hub.c:2225 hub_port_connect drivers/usb/core/hub.c:4949 [inline] hub_port_connect_change drivers/usb/core/hub.c:5213 [inline] port_event drivers/usb/core/hub.c:5359 [inline] hub_event+0x1454/0x3640 drivers/usb/core/hub.c:5441 process_one_work+0x92b/0x1530 kernel/workqueue.c:2269 worker_thread+0x96/0xe20 kernel/workqueue.c:2415 kthread+0x318/0x420 kernel/kthread.c:255 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352 The buggy address belongs to the object at 8881d644bb80 which belongs to the cache kmalloc-2k of size 2048 The buggy address is located 504 bytes inside of 2048-byte region [8881d644bb80, 8881d644c380) The buggy address belongs to the page: page:ea0007591200 refcount:1 mapcount:0 mapping:8881da00c000 index:0x8881d6448000 compound_mapcount: 0 flags: 0x2010200(slab|head) raw: 02010200 ea000760ac00 00020002 8881da00c000 raw: 8881d6448000 800f000a 0001 page dumped because: kasan: bad access detected Memory state around the buggy address: 8881d644bc00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb 8881d644bc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb 8881d644bd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ 8881d644bd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb 8881d644be00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb == Tested on: commit: eea39f24 usb-fuzzer: main usb gadget fuzzer driver git tree: https://github.com/google/kasan.git console output: https://syzkaller.appspot.com/x/log.txt?x=1018661e60 kernel config:
Re: WARNING in r871xu_dev_remove
Am Donnerstag, den 22.08.2019, 07:28 -0700 schrieb syzbot: > Hello, > > syzbot found the following crash on: > > HEAD commit:eea39f24 usb-fuzzer: main usb gadget fuzzer driver > git tree: https://github.com/google/kasan.git usb-fuzzer > console output: https://syzkaller.appspot.com/x/log.txt?x=163ae01260 > kernel config: https://syzkaller.appspot.com/x/.config?x=d0c62209eedfd54e > dashboard link: https://syzkaller.appspot.com/bug?extid=80899a8a8efe8968cde7 > compiler: gcc (GCC) 9.0.0 20181231 (experimental) > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1739cb0e60 > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=154fcc2e60 > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > Reported-by: syzbot+80899a8a8efe8968c...@syzkaller.appspotmail.com #syz test: https://github.com/google/kasan.git eea39f24 >From 4f21b5aabc448719aa612b9359d90a178cb485d8 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Thu, 22 Aug 2019 16:37:33 +0200 Subject: [PATCH] rtl8712: fix race between firmware failing to load and disconnect We have to wait for the attempt to load the firmware to finish before we evaluate the result. Reported-by: syzbot+80899a8a8efe8968c...@syzkaller.appspotmail.com Signed-off-by: Oliver Neukum --- drivers/staging/rtl8712/hal_init.c | 3 ++- drivers/staging/rtl8712/usb_intf.c | 8 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c index 40145c0338e4..42c0a3c947f1 100644 --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -33,7 +33,6 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context) { struct _adapter *adapter = context; - complete(>rtl8712_fw_ready); if (!firmware) { struct usb_device *udev = adapter->dvobjpriv.pusbdev; struct usb_interface *usb_intf = adapter->pusb_intf; @@ -41,11 +40,13 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context) dev_err(>dev, "r8712u: Firmware request failed\n"); usb_put_dev(udev); usb_set_intfdata(usb_intf, NULL); + complete(>rtl8712_fw_ready); return; } adapter->fw = firmware; /* firmware available - start netdev */ register_netdev(adapter->pnetdev); + complete(>rtl8712_fw_ready); } static const char firmware_file[] = "rtlwifi/rtl8712u.bin"; diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c index d0daae0b8299..8d7b57073592 100644 --- a/drivers/staging/rtl8712/usb_intf.c +++ b/drivers/staging/rtl8712/usb_intf.c @@ -595,10 +595,13 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf) if (pnetdev) { struct _adapter *padapter = netdev_priv(pnetdev); - usb_set_intfdata(pusb_intf, NULL); - release_firmware(padapter->fw); /* never exit with a firmware callback pending */ wait_for_completion(>rtl8712_fw_ready); + pnetdev = usb_get_intfdata(pusb_intf); + usb_set_intfdata(pusb_intf, NULL); + if (!pnetdev) + goto raced_with_firmware_failure; + release_firmware(padapter->fw); if (drvpriv.drv_registered) padapter->surprise_removed = true; unregister_netdev(pnetdev); /* will call netdev_close() */ @@ -609,6 +612,7 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf) r871x_dev_unload(padapter); r8712_free_drv_sw(padapter); +raced_with_firmware_failure: /* decrease the reference count of the usb device structure * when disconnect */ -- 2.16.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
WARNING in r871xu_dev_remove
Hello, syzbot found the following crash on: HEAD commit:eea39f24 usb-fuzzer: main usb gadget fuzzer driver git tree: https://github.com/google/kasan.git usb-fuzzer console output: https://syzkaller.appspot.com/x/log.txt?x=163ae01260 kernel config: https://syzkaller.appspot.com/x/.config?x=d0c62209eedfd54e dashboard link: https://syzkaller.appspot.com/bug?extid=80899a8a8efe8968cde7 compiler: gcc (GCC) 9.0.0 20181231 (experimental) syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1739cb0e60 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=154fcc2e60 IMPORTANT: if you fix the bug, please add the following tag to the commit: Reported-by: syzbot+80899a8a8efe8968c...@syzkaller.appspotmail.com [ cut here ] WARNING: CPU: 1 PID: 83 at net/core/dev.c:8167 rollback_registered_many.cold+0x41/0x1bc net/core/dev.c:8167 Kernel panic - not syncing: panic_on_warn set ... CPU: 1 PID: 83 Comm: kworker/1:2 Not tainted 5.3.0-rc5+ #28 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: usb_hub_wq hub_event Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xca/0x13e lib/dump_stack.c:113 panic+0x2a3/0x6da kernel/panic.c:219 __warn.cold+0x20/0x4a kernel/panic.c:576 report_bug+0x262/0x2a0 lib/bug.c:186 fixup_bug arch/x86/kernel/traps.c:179 [inline] fixup_bug arch/x86/kernel/traps.c:174 [inline] do_error_trap+0x12b/0x1e0 arch/x86/kernel/traps.c:272 do_invalid_op+0x32/0x40 arch/x86/kernel/traps.c:291 invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1028 RIP: 0010:rollback_registered_many.cold+0x41/0x1bc net/core/dev.c:8167 Code: ff e8 c7 26 90 fc 48 c7 c7 40 ec 63 86 e8 24 c8 7a fc 0f 0b e9 93 be ff ff e8 af 26 90 fc 48 c7 c7 40 ec 63 86 e8 0c c8 7a fc <0f> 0b 4c 89 e7 e8 f9 12 34 fd 31 ff 41 89 c4 89 c6 e8 bd 27 90 fc RSP: 0018:8881d938f6a8 EFLAGS: 00010286 RAX: 0024 RBX: 8881d2a1 RCX: RDX: RSI: 81288cfd RDI: ed103b271ec7 RBP: 8881d938f7d8 R08: 0024 R09: fbfff11ad794 R10: fbfff11ad793 R11: 88d6bc9f R12: 8881d2a10070 R13: 8881d938f768 R14: dc00 R15: rollback_registered+0xf2/0x1c0 net/core/dev.c:8243 unregister_netdevice_queue net/core/dev.c:9290 [inline] unregister_netdevice_queue+0x1d7/0x2b0 net/core/dev.c:9283 unregister_netdevice include/linux/netdevice.h:2631 [inline] unregister_netdev+0x18/0x20 net/core/dev.c:9331 r871xu_dev_remove+0xe2/0x215 drivers/staging/rtl8712/usb_intf.c:604 usb_unbind_interface+0x1bd/0x8a0 drivers/usb/core/driver.c:423 __device_release_driver drivers/base/dd.c:1134 [inline] device_release_driver_internal+0x42f/0x500 drivers/base/dd.c:1165 bus_remove_device+0x2dc/0x4a0 drivers/base/bus.c:556 device_del+0x420/0xb10 drivers/base/core.c:2339 usb_disable_device+0x211/0x690 drivers/usb/core/message.c:1237 usb_disconnect+0x284/0x8d0 drivers/usb/core/hub.c:2199 hub_port_connect drivers/usb/core/hub.c:4949 [inline] hub_port_connect_change drivers/usb/core/hub.c:5213 [inline] port_event drivers/usb/core/hub.c:5359 [inline] hub_event+0x1454/0x3640 drivers/usb/core/hub.c:5441 process_one_work+0x92b/0x1530 kernel/workqueue.c:2269 process_scheduled_works kernel/workqueue.c:2331 [inline] worker_thread+0x7ab/0xe20 kernel/workqueue.c:2417 kthread+0x318/0x420 kernel/kthread.c:255 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352 Kernel Offset: disabled Rebooting in 86400 seconds.. --- This bug 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 syzkal...@googlegroups.com. syzbot will keep track of this bug report. See: https://goo.gl/tpsmEJ#status for how to communicate with syzbot. syzbot can test patches for this bug, for details see: https://goo.gl/tpsmEJ#testing-patches ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel