Skip to content

Commit 03f36e8

Browse files
Oliver Neukumgregkh
authored andcommitted
USB: open disconnect race in iowarrior
the driver sets intfdata to NULL without lock. Data structures can be freed and accessed. Signed-off-by: Oliver Neukum <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5919a43 commit 03f36e8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/usb/misc/iowarrior.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module_param(debug, bool, 0644);
6666
MODULE_PARM_DESC(debug, "debug=1 enables debugging messages");
6767

6868
static struct usb_driver iowarrior_driver;
69+
static DEFINE_MUTEX(iowarrior_open_disc_lock);
6970

7071
/*--------------*/
7172
/* data */
@@ -608,11 +609,15 @@ static int iowarrior_open(struct inode *inode, struct file *file)
608609
return -ENODEV;
609610
}
610611

612+
mutex_lock(&iowarrior_open_disc_lock);
611613
dev = usb_get_intfdata(interface);
612-
if (!dev)
614+
if (!dev) {
615+
mutex_unlock(&iowarrior_open_disc_lock);
613616
return -ENODEV;
617+
}
614618

615619
mutex_lock(&dev->mutex);
620+
mutex_unlock(&iowarrior_open_disc_lock);
616621

617622
/* Only one process can open each device, no sharing. */
618623
if (dev->opened) {
@@ -866,6 +871,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
866871
int minor;
867872

868873
dev = usb_get_intfdata(interface);
874+
mutex_lock(&iowarrior_open_disc_lock);
869875
usb_set_intfdata(interface, NULL);
870876

871877
minor = dev->minor;
@@ -879,6 +885,7 @@ static void iowarrior_disconnect(struct usb_interface *interface)
879885
dev->present = 0;
880886

881887
mutex_unlock(&dev->mutex);
888+
mutex_unlock(&iowarrior_open_disc_lock);
882889

883890
if (dev->opened) {
884891
/* There is a process that holds a filedescriptor to the device ,

0 commit comments

Comments
 (0)