[PATCH v2 06/12] USB: serial: io_edgeport: fix potential use-after-free on disconnect

From: Johan Hovold

Date: Fri Oct 23 2026 - 08:18:02 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
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