Skip to content

Commit b5f8d46

Browse files
jhovoldgregkh
authored andcommitted
USB: iowarrior: fix use-after-free after driver unbind
Make sure to stop also the asynchronous write URBs on disconnect() to avoid use-after-free in the completion handler after driver unbind. Fixes: 946b960 ("USB: add driver for iowarrior devices.") Cc: stable <[email protected]> # 2.6.21: 51a2f07 ("USB: introduce usb_anchor") Signed-off-by: Johan Hovold <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 80cd547 commit b5f8d46

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/usb/misc/iowarrior.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct iowarrior {
8787
char chip_serial[9]; /* the serial number string of the chip connected */
8888
int report_size; /* number of bytes in a report */
8989
u16 product_id;
90+
struct usb_anchor submitted;
9091
};
9192

9293
/*--------------*/
@@ -425,11 +426,13 @@ static ssize_t iowarrior_write(struct file *file,
425426
retval = -EFAULT;
426427
goto error;
427428
}
429+
usb_anchor_urb(int_out_urb, &dev->submitted);
428430
retval = usb_submit_urb(int_out_urb, GFP_KERNEL);
429431
if (retval) {
430432
dev_dbg(&dev->interface->dev,
431433
"submit error %d for urb nr.%d\n",
432434
retval, atomic_read(&dev->write_busy));
435+
usb_unanchor_urb(int_out_urb);
433436
goto error;
434437
}
435438
/* submit was ok */
@@ -770,6 +773,8 @@ static int iowarrior_probe(struct usb_interface *interface,
770773
iface_desc = interface->cur_altsetting;
771774
dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
772775

776+
init_usb_anchor(&dev->submitted);
777+
773778
res = usb_find_last_int_in_endpoint(iface_desc, &dev->int_in_endpoint);
774779
if (res) {
775780
dev_err(&interface->dev, "no interrupt-in endpoint found\n");
@@ -885,6 +890,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
885890
Deleting the device is postponed until close() was called.
886891
*/
887892
usb_kill_urb(dev->int_in_urb);
893+
usb_kill_anchored_urbs(&dev->submitted);
888894
wake_up_interruptible(&dev->read_wait);
889895
wake_up_interruptible(&dev->write_wait);
890896
mutex_unlock(&dev->mutex);

0 commit comments

Comments
 (0)