Commit 1c4259ab authored by Johan Hovold's avatar Johan Hovold Committed by Khalid Elmously

USB: iowarrior: fix use-after-free after driver unbind

BugLink: https://bugs.launchpad.net/bugs/1848780

commit b5f8d468 upstream.

Make sure to stop also the asynchronous write URBs on disconnect() to
avoid use-after-free in the completion handler after driver unbind.

Fixes: 946b960d ("USB: add driver for iowarrior devices.")
Cc: stable <stable@vger.kernel.org>	# 2.6.21: 51a2f077 ("USB: introduce usb_anchor")
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20191009104846.5925-4-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 6c4624d7
...@@ -89,6 +89,7 @@ struct iowarrior { ...@@ -89,6 +89,7 @@ struct iowarrior {
char chip_serial[9]; /* the serial number string of the chip connected */ char chip_serial[9]; /* the serial number string of the chip connected */
int report_size; /* number of bytes in a report */ int report_size; /* number of bytes in a report */
u16 product_id; u16 product_id;
struct usb_anchor submitted;
}; };
/*--------------*/ /*--------------*/
...@@ -437,11 +438,13 @@ static ssize_t iowarrior_write(struct file *file, ...@@ -437,11 +438,13 @@ static ssize_t iowarrior_write(struct file *file,
retval = -EFAULT; retval = -EFAULT;
goto error; goto error;
} }
usb_anchor_urb(int_out_urb, &dev->submitted);
retval = usb_submit_urb(int_out_urb, GFP_KERNEL); retval = usb_submit_urb(int_out_urb, GFP_KERNEL);
if (retval) { if (retval) {
dev_dbg(&dev->interface->dev, dev_dbg(&dev->interface->dev,
"submit error %d for urb nr.%d\n", "submit error %d for urb nr.%d\n",
retval, atomic_read(&dev->write_busy)); retval, atomic_read(&dev->write_busy));
usb_unanchor_urb(int_out_urb);
goto error; goto error;
} }
/* submit was ok */ /* submit was ok */
...@@ -788,6 +791,8 @@ static int iowarrior_probe(struct usb_interface *interface, ...@@ -788,6 +791,8 @@ static int iowarrior_probe(struct usb_interface *interface,
iface_desc = interface->cur_altsetting; iface_desc = interface->cur_altsetting;
dev->product_id = le16_to_cpu(udev->descriptor.idProduct); dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
init_usb_anchor(&dev->submitted);
/* set up the endpoint information */ /* set up the endpoint information */
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
endpoint = &iface_desc->endpoint[i].desc; endpoint = &iface_desc->endpoint[i].desc;
...@@ -917,6 +922,7 @@ static void iowarrior_disconnect(struct usb_interface *interface) ...@@ -917,6 +922,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
Deleting the device is postponed until close() was called. Deleting the device is postponed until close() was called.
*/ */
usb_kill_urb(dev->int_in_urb); usb_kill_urb(dev->int_in_urb);
usb_kill_anchored_urbs(&dev->submitted);
wake_up_interruptible(&dev->read_wait); wake_up_interruptible(&dev->read_wait);
wake_up_interruptible(&dev->write_wait); wake_up_interruptible(&dev->write_wait);
mutex_unlock(&dev->mutex); mutex_unlock(&dev->mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment