patch "USB: iowarrior: fix use-after-free on disconnect" added to usb-linus
Subsystems (2)
This is a note to let you know that I've just added the patch titled
USB: iowarrior: fix use-after-free on disconnect
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From edc4746f253d907d048de680a621e121517f484b Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Wed, 9 Oct 2019 12:48:41 +0200
Subject: USB: iowarrior: fix use-after-free on disconnect
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().
--- drivers/usb/misc/iowarrior.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/misc/iowarrior.c +3 -4
@@ -866,8 +866,6 @@ static void iowarrior_disconnect(struct usb_interface *interface) dev =usb_get_intfdata (interface);mutex_lock (&iowarrior_open_disc_lock);usb_set_intfdata (interface,NULL ); -/* prevent device read, write and ioctl */ - dev->present =0 ; minor = dev->minor;mutex_unlock (&iowarrior_open_disc_lock);
@@ -878,8 +876,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)mutex_lock (&dev->mutex);/* prevent device read, write and ioctl */ - -mutex_unlock (&dev->mutex); + dev->present =0 ;if (dev->opened) {/* There is a process that holds a filedescriptor to the device ,
@@ -889,8 +886,10 @@ static void iowarrior_disconnect(struct usb_interface *interface)usb_kill_urb (dev->int_in_urb);wake_up_interruptible (&dev->read_wait);wake_up_interruptible (&dev->write_wait); +mutex_unlock (&dev->mutex); }else {/* no process is using the device, cleanup now */ +mutex_unlock (&dev->mutex);iowarrior_delete (dev); }
Signature · 1 line
2.23.0