From: sashiko-bot@kernel.org
To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] USB: serial: opticon: fix use-after-free in write completion
Date: Mon, 30 Nov 2026 12:06:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-241018@kernel.org> (raw)
In-Reply-To: <20261130114616.31927-1-25031212351@stu.xidian.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: serial: opticon: use-after-free of port via work queued in
port_remove()
--
commit 4e868399fee2ff649a085893481b9d2e4c6c3450
Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
USB: serial: opticon: fix use-after-free in write completion
This commit kills anchored write URBs in opticon_port_remove() before
freeing the port's private data to prevent a use-after-free on deferred URB
giveback.
> diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
> index 152dfc901cd8f..af53ed13577e9 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);
> }
[Severity: High]
Can killing anchored write URBs in opticon_port_remove() cause a
use-after-free of struct usb_serial_port via port->work?
When usb_kill_anchored_urbs() kills an in-flight write URB here, it
synchronously runs opticon_write_control_callback(), which unconditionally
schedules port->work:
drivers/usb/serial/opticon.c:opticon_write_control_callback() {
...
spin_lock_irqsave(&priv->lock, flags);
--priv->outstanding_urbs;
priv->outstanding_bytes -= urb->transfer_buffer_length;
spin_unlock_irqrestore(&priv->lock, flags);
usb_serial_port_softint(port);
}
In usb_serial_disconnect(), cancel_work_sync(&port->work) runs in the first
port loop before device_del(&port->dev) invokes opticon_port_remove().
Nothing cancels port->work after opticon_port_remove() returns, so when the
tty has already been closed, usb_serial_put() immediately frees port in
usb_serial_port_release() while port->work (usb_serial_port_work) is still
queued:
CPU0 CPU1 (system_wq)
usb_serial_disconnect()
cancel_work_sync(&port->work)
device_del(&port->dev)
...
opticon_port_remove()
usb_kill_anchored_urbs()
...
opticon_write_control_callback()
usb_serial_port_softint(port)
schedule_work(&port->work)
usb_serial_put(serial)
...
usb_serial_port_release()
kfree(port)
usb_serial_port_work()
tty_port_tty_wakeup(&port->port)
<-- use-after-free
Cancelling port->work after usb_kill_anchored_urbs() (or not scheduling
port->work when the URB fails with -ENOENT) would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130114616.31927-1-25031212351@stu.xidian.edu.cn?part=1
prev parent reply other threads:[~2026-11-30 12:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 11:46 [PATCH] USB: serial: opticon: fix use-after-free in write completion YuanZhe Liu
2026-11-30 12:06 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-241018@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=25031212351@stu.xidian.edu.cn \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox