The write URBs are anchored in a per-port anchor that is embedded in the driver's private data, but the anchor is never drained when the port is removed. The close callback does kill the anchored URBs, but it runs before the line discipline is released: tty_release() calls ->close() before tty_ldisc_release(), and some line disciplines (e.g. ppp) call tty->ops->write() directly from their transmit path. A write submitted after the close callback has drained the anchor will therefore remain in flight until the port is removed, where the deferred giveback of the URB accesses the already freed private data: BUG: KASAN: slab-use-after-free in usb_anchor_suspend_wakeups Write of size 4 at addr ... ... usb_anchor_suspend_wakeups __usb_hcd_giveback_urb ... Freed by task 11: ... usb_serial_device_remove ... kfree Fix this by killing any anchored URBs in port_remove() before freeing the private data, as is already done by the garmin_gps driver. Fixes: e6421583953f ("USB: serial: opticon: stop all I/O on close()") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- drivers/usb/serial/opticon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index 152dfc901cd8..af53ed13577e 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c @@ -368,6 +368,7 @@ static void opticon_port_remove(struct usb_serial_port *port) { struct opticon_private *priv = usb_get_serial_port_data(port); + usb_kill_anchored_urbs(&priv->anchor); kfree(priv); } -- 2.34.1