From: Johan Hovold <johan@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v2 06/12] USB: serial: io_edgeport: fix potential use-after-free on disconnect
Date: Fri, 23 Oct 2026 14:15:24 +0200 [thread overview]
Message-ID: <20261023121530.186541-7-johan@kernel.org> (raw)
In-Reply-To: <20261023121530.186541-1-johan@kernel.org>
The driver submits command URBs asynchronously but fails to stop them on
disconnect, something which could lead to a use-after-free when
accessing driver data in the completion handler after a port has been
unbound.
Add an URB anchor to track and kill outstanding command URBs on
disconnect.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/io_edgeport.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index b8fbcc8908d1..0fe7495c47f4 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -225,6 +225,7 @@ struct edgeport_serial {
__u8 rxStatusParam; /* the receive status parameter */
__s16 rxBytesRemaining; /* the number of port bytes left to read */
struct usb_serial *serial; /* loop back to the owner of this object */
+ struct usb_anchor cmd_anchor;
};
/* baud rate information */
@@ -261,9 +262,6 @@ static const struct divisor_table_entry divisor_table[] = {
{ 230400, 1},
};
-/* Number of outstanding Command Write Urbs */
-static atomic_t CmdUrbs = ATOMIC_INIT(0);
-
/* function prototypes */
@@ -776,11 +774,6 @@ static void edge_bulk_out_cmd_callback(struct urb *urb)
struct device *dev = &urb->dev->dev;
int status = urb->status;
- atomic_dec(&CmdUrbs);
- dev_dbg(dev, "%s - FREE URB %p (outstanding %d)\n", __func__, urb,
- atomic_read(&CmdUrbs));
-
-
/* clean up the transfer buffer */
kfree(urb->transfer_buffer);
@@ -2127,24 +2120,21 @@ static int write_cmd_usb(struct edgeport_port *edge_port,
if (!urb)
return -ENOMEM;
- atomic_inc(&CmdUrbs);
- dev_dbg(dev, "%s - ALLOCATE URB %p (outstanding %d)\n",
- __func__, urb, atomic_read(&CmdUrbs));
-
usb_fill_bulk_urb(urb, edge_serial->serial->dev,
usb_sndbulkpipe(edge_serial->serial->dev,
edge_serial->bulk_out_endpoint),
buffer, length, edge_bulk_out_cmd_callback, edge_port);
edge_port->commandPending = true;
+ usb_anchor_urb(urb, &edge_serial->cmd_anchor);
status = usb_submit_urb(urb, GFP_ATOMIC);
if (status) {
/* something went wrong */
dev_err(dev, "%s - usb_submit_urb(write command) failed, status = %d\n",
__func__, status);
+ usb_unanchor_urb(urb);
usb_free_urb(urb);
- atomic_dec(&CmdUrbs);
return status;
}
@@ -2696,6 +2686,7 @@ static int edge_startup(struct usb_serial *serial)
spin_lock_init(&edge_serial->es_lock);
edge_serial->serial = serial;
+ init_usb_anchor(&edge_serial->cmd_anchor);
usb_set_serial_data(serial, edge_serial);
/* get the name for the device from the device */
@@ -2900,6 +2891,8 @@ static void edge_disconnect(struct usb_serial *serial)
{
struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
+ usb_kill_anchored_urbs(&edge_serial->cmd_anchor);
+
if (edge_serial->is_epic) {
usb_kill_urb(edge_serial->interrupt_read_urb);
usb_kill_urb(edge_serial->read_urb);
--
2.55.0
next prev parent reply other threads:[~2026-10-23 12:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 12:15 [PATCH v2 00/12] USB: serial: io_edgeport: fixes and sync commands Johan Hovold
2026-10-23 12:15 ` [PATCH v2 01/12] USB: serial: io_edgeport: fix NULL-deref on early status Johan Hovold
2026-10-23 12:15 ` [PATCH v2 02/12] USB: serial: io_edgeport: fix potential close() use-after-free Johan Hovold
2026-10-23 12:15 ` [PATCH v2 03/12] USB: serial: io_edgeport: fix potential NULL-deref at open Johan Hovold
2026-10-23 12:15 ` [PATCH v2 04/12] USB: serial: io_edgeport: move initial termios update to open() Johan Hovold
2026-10-23 12:15 ` [PATCH v2 05/12] USB: serial: io_edgeport: fix potential fifo corruption Johan Hovold
2026-10-23 12:15 ` Johan Hovold [this message]
2026-10-23 12:15 ` [PATCH v2 07/12] USB: serial: io_edgeport: serialise MCR accesses Johan Hovold
2026-10-23 12:15 ` [PATCH v2 08/12] USB: serial: io_edgeport: drop redundant sanity checks Johan Hovold
2026-10-23 12:15 ` [PATCH v2 09/12] USB: serial: io_edgeport: drop redundant open " Johan Hovold
2026-10-23 12:15 ` [PATCH v2 10/12] USB: serial: io_edgeport: deassert DTR/RTS on close() and B0 Johan Hovold
2026-10-23 12:15 ` [PATCH v2 11/12] USB: serial: io_edgeport: replace atomic command allocations Johan Hovold
2026-10-23 12:15 ` [PATCH v2 12/12] USB: serial: io_edgeport: switch to synchronous commands Johan Hovold
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=20261023121530.186541-7-johan@kernel.org \
--to=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®