Skip to contentSkip to conversation

usbnet: Prevents free active kevent

PATCH Superseded Lizhi Xu 2 participants 3 messages Oct 18, 2025 – Oct 22, 2025

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Lizhi Xu

author
#0 lore raw

PATCH v3 1/1 usbnet: Prevents free active kevent

The root cause of this issue are:
1. When probing the usbnet device, executing usbnet_link_change(dev, 0, 0); put the kevent work in global workqueue. However, the kevent has not yet been scheduled when the usbnet device is unregistered. Therefore, executing free_netdev() results in the "free active object (kevent)" error reported here.

2. Another factor is that when calling usbnet_disconnect()->unregister_netdev(), if the usbnet device is up, ndo_stop() is executed to cancel the kevent. However, because the device is not up, ndo_stop() is not executed.

The solution to this problem is to cancel the kevent before executing free_netdev(), which also deletes the delay timer.

Fixes a69e617e533e ("usbnet: Fix linkwatch use-after-free on disconnect")

---
V1 -> V2: update comments for typos
V2 -> V3: add fixes tag

 drivers/net/usb/usbnet.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/usb/usbnet.c +3 -0
index bf01f2728531..f0294f0e6612 100644
@@ -1672,6 +1672,9 @@ void usbnet_disconnect (struct usb_interface *intf)
 	usb_free_urb(dev->interrupt);
 	kfree(dev->padding_pkt);
 
+	cancel_work_sync(&dev->kevent);
+	timer_delete_sync(&dev->delay);
+
 	free_netdev(net);
 }
 EXPORT_SYMBOL_GPL(usbnet_disconnect);
Signature · 1 line
2.43.0
maintainer
#1 lore raw

drivers/net/usb/usbnet.c void usbnet_disconnect (struct usb_interface *intf) · line 1678

Quoted 10 lines · On Sat, 18 Oct 2025 22:49:40 +0800 Lizhi Xu wrote:
drivers/net/usb/usbnet.c +3 -0
@@ -1672,6 +1672,9 @@ void usbnet_disconnect (struct usb_interface *intf)
 	usb_free_urb(dev->interrupt);
 	kfree(dev->padding_pkt);
 
+	cancel_work_sync(&dev->kevent);
+	timer_delete_sync(&dev->delay);
+
 	free_netdev(net);

Is this the best spot to place the cancel?
I think it may be better right after unregister_netdev(). I haven't analyze this driver too closely but for example since kevent may call the sub-driver having it running after we already called dev->driver_info->unbind() seems risky.

Signature · 1 line
pw-bot: cr
author
#2 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 6 lines
drivers/net/usb/usbnet.c +0 -0
@@ -1672,6 +1672,9 @@ void usbnet_disconnect (struct usb_interface *intf)
 	usb_free_urb(dev->interrupt);
 	kfree(dev->padding_pkt);
 
Quoted 10 lines

drivers/net/usb/usbnet.c void usbnet_disconnect (struct usb_interface *intf) · line 1678

Quoted 4 lines
drivers/net/usb/usbnet.c +3 -0
+	cancel_work_sync(&dev->kevent);
+	timer_delete_sync(&dev->delay);
+
 	free_netdev(net);

Is this the best spot to place the cancel?
I think it may be better right after unregister_netdev(). I haven't analyze this driver too closely but for example since kevent may call the sub-driver having it running after we already called dev->driver_info->unbind() seems risky.

I agree with your analysis. I'll update the patch and release a new version.

BR,
Lizhi