Commit 2fdcf7e1 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: iowarrior: fix use-after-free on disconnect

commit edc4746f upstream.

A recent fix addressing a deadlock on disconnect introduced a new bug
by moving the present flag out of the critical section protected by the
driver-data mutex. This could lead to a racing release() freeing the
driver data before disconnect() is done with it.

Due to insufficient locking a related use-after-free could be triggered
also before the above mentioned commit. Specifically, the driver needs
to hold the driver-data mutex also while checking the opened flag at
disconnect().

Fixes: c468a8aa ("usb: iowarrior: fix deadlock on disconnect")
Fixes: 946b960d ("USB: add driver for iowarrior devices.")
Cc: stable <stable@vger.kernel.org>	# 2.6.21
Reported-by: syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20191009104846.5925-2-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ab162d33
...@@ -866,8 +866,6 @@ static void iowarrior_disconnect(struct usb_interface *interface) ...@@ -866,8 +866,6 @@ static void iowarrior_disconnect(struct usb_interface *interface)
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
mutex_lock(&iowarrior_open_disc_lock); mutex_lock(&iowarrior_open_disc_lock);
usb_set_intfdata(interface, NULL); usb_set_intfdata(interface, NULL);
/* prevent device read, write and ioctl */
dev->present = 0;
minor = dev->minor; minor = dev->minor;
mutex_unlock(&iowarrior_open_disc_lock); mutex_unlock(&iowarrior_open_disc_lock);
...@@ -878,8 +876,7 @@ static void iowarrior_disconnect(struct usb_interface *interface) ...@@ -878,8 +876,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
mutex_lock(&dev->mutex); mutex_lock(&dev->mutex);
/* prevent device read, write and ioctl */ /* prevent device read, write and ioctl */
dev->present = 0;
mutex_unlock(&dev->mutex);
if (dev->opened) { if (dev->opened) {
/* There is a process that holds a filedescriptor to the device , /* There is a process that holds a filedescriptor to the device ,
...@@ -889,8 +886,10 @@ static void iowarrior_disconnect(struct usb_interface *interface) ...@@ -889,8 +886,10 @@ static void iowarrior_disconnect(struct usb_interface *interface)
usb_kill_urb(dev->int_in_urb); usb_kill_urb(dev->int_in_urb);
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);
} else { } else {
/* no process is using the device, cleanup now */ /* no process is using the device, cleanup now */
mutex_unlock(&dev->mutex);
iowarrior_delete(dev); iowarrior_delete(dev);
} }
......
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