Skip to content

Commit c43122f

Browse files
Fan Wumarckleinebudde
authored andcommitted
can: esd_usb: kill anchored URBs before freeing netdevs
esd_usb_disconnect() frees each CAN netdev with free_candev() inside its per-netdev loop and only calls unlink_all_urbs(dev) afterwards. The per-netdev private data (struct esd_usb_net_priv) is embedded in the net_device allocation returned by alloc_candev(), so once free_candev() has run, dev->nets[i] points to freed memory. unlink_all_urbs() then dereferences the freed dev->nets[i] to kill the per-netdev TX anchor (usb_kill_anchored_urbs(&priv->tx_submitted)), clear active_tx_jobs, and reset priv->tx_contexts[]. Reorder the teardown so the anchored URBs are killed before the netdevs are freed, matching other CAN/USB drivers in the same directory such as ems_usb, usb_8dev and mcba_usb, which unregister, then unlink, then free: unregister the netdevs first (which stops their TX queues), call unlink_all_urbs(dev) once, then free the netdevs. This issue was found by an in-house static analysis tool. Fixes: 96d8e90 ("can: Add driver for esd CAN-USB/2 device") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.5 Signed-off-by: Fan Wu <fanwu01@zju.edu.cn> Link: https://patch.msgid.link/20260709164159.497640-1-fanwu01@zju.edu.cn Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 79adf48 commit c43122f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/net/can/usb/esd_usb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,13 @@ static void esd_usb_disconnect(struct usb_interface *intf)
13901390
netdev = dev->nets[i]->netdev;
13911391
netdev_info(netdev, "unregister\n");
13921392
unregister_netdev(netdev);
1393-
free_candev(netdev);
13941393
}
13951394
}
13961395
unlink_all_urbs(dev);
1396+
for (i = 0; i < dev->net_count; i++) {
1397+
if (dev->nets[i])
1398+
free_candev(dev->nets[i]->netdev);
1399+
}
13971400
kfree(dev);
13981401
}
13991402
}

0 commit comments

Comments
 (0)