mcba_urb_unlink() frees the RX buffers but leaves the stale pointers in priv->rxbuf[]. It runs from both mcba_usb_close() and mcba_usb_disconnect(), so once the interface has been up, the buffers are freed twice: on unplug after "ip link set can0 down", on unplug while can0 is up, or on a second up/down cycle. No special device behaviour is needed; on a host controller without DMA the double usb_free_coherent() is a double kfree(). Clear each rxbuf[] pointer after freeing it, which makes the function safe to call twice again, as it was before commit 91c02557174b ("can: mcba_usb: fix memory leak in mcba_usb"). The bug was found, and the reproducer and this fix were written, by AI agents (Claude Mythos and Claude Opus models). The analysis and the patch were reviewed by a human. Fixes: 91c02557174b ("can: mcba_usb: fix memory leak in mcba_usb") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Becholey --- An emulated adapter on dummy_hcd: "ip link set can0 up/down", then unplug, gives a KASAN double-free in hcd_buffer_free() on v7.3.1 and master 9d66f26fefac; the two other sequences as well. All clean with the fix, and a second "ip link set up" still works. Reproducer available on request. drivers/net/can/usb/mcba_usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c index 04170326dc7e..b40b323da9d3 100644 --- a/drivers/net/can/usb/mcba_usb.c +++ b/drivers/net/can/usb/mcba_usb.c @@ -718,9 +718,11 @@ static void mcba_urb_unlink(struct mcba_priv *priv) usb_kill_anchored_urbs(&priv->rx_submitted); - for (i = 0; i < MCBA_MAX_RX_URBS; ++i) + for (i = 0; i < MCBA_MAX_RX_URBS; ++i) { usb_free_coherent(priv->udev, MCBA_USB_RX_BUFF_SIZE, priv->rxbuf[i], priv->rxbuf_dma[i]); + priv->rxbuf[i] = NULL; + } usb_kill_anchored_urbs(&priv->tx_submitted); }