Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] USB: serial: opticon: fix use-after-free in write completion
@ 2026-11-30 12:22 YuanZhe Liu
  2026-11-30 12:46 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-11-30 12:22 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Bin Yu,
	Cheng Wen

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.  The
completion handler also queues the port work, which
usb_serial_disconnect() cancelled before removing the port, so cancel
the work again before returning.

Fixes: e6421583953f ("USB: serial: opticon: stop all I/O on close()")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
v2:
- Cancel the port work queued by the completion handler: it is
  queued after usb_serial_disconnect() cancelled it and could
  otherwise outlive the port.

 drivers/usb/serial/opticon.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index 152dfc901cd8..3477faff1e24 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -368,6 +368,12 @@ 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);
+	/*
+	 * Killing the anchored URBs may have run the completion handler,
+	 * which queues the port work after usb_serial_disconnect() cancelled it.
+	 */
+	cancel_work_sync(&port->work);
 	kfree(priv);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 12:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:22 [PATCH v2] USB: serial: opticon: fix use-after-free in write completion YuanZhe Liu
2026-11-30 12:46 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox