[PATCH] USB: serial: opticon: fix use-after-free in write completion
From: YuanZhe Liu
Date: Mon Nov 30 2026 - 06:46:39 EST
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@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
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