Skip to content

Commit d5d1cea

Browse files
Oliver Neukumgregkh
authored andcommitted
USB: open disconnect race in usblcd
this driver has a possible use after free due to a race when disconnect and open handle intfdata without a lock. Signed-off-by: Oliver Neukum <oneukum@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 78663ec commit d5d1cea

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎drivers/usb/misc/usblcd.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/init.h>
1818
#include <linux/slab.h>
1919
#include <linux/errno.h>
20+
#include <linux/mutex.h>
2021
#include <asm/uaccess.h>
2122
#include <linux/usb.h>
2223

@@ -34,6 +35,8 @@ static struct usb_device_id id_table [] = {
3435
};
3536
MODULE_DEVICE_TABLE (usb, id_table);
3637

38+
static DEFINE_MUTEX(open_disc_mutex);
39+
3740

3841
struct usb_lcd {
3942
struct usb_device * udev; /* init: probe_lcd */
@@ -79,12 +82,16 @@ static int lcd_open(struct inode *inode, struct file *file)
7982
return -ENODEV;
8083
}
8184

85+
mutex_lock(&open_disc_mutex);
8286
dev = usb_get_intfdata(interface);
83-
if (!dev)
87+
if (!dev) {
88+
mutex_unlock(&open_disc_mutex);
8489
return -ENODEV;
90+
}
8591

8692
/* increment our usage count for the device */
8793
kref_get(&dev->kref);
94+
mutex_unlock(&open_disc_mutex);
8895

8996
/* grab a power reference */
9097
r = usb_autopm_get_interface(interface);
@@ -393,8 +400,10 @@ static void lcd_disconnect(struct usb_interface *interface)
393400
struct usb_lcd *dev;
394401
int minor = interface->minor;
395402

403+
mutex_lock(&open_disc_mutex);
396404
dev = usb_get_intfdata(interface);
397405
usb_set_intfdata(interface, NULL);
406+
mutex_unlock(&open_disc_mutex);
398407

399408
/* give back our minor */
400409
usb_deregister_dev(interface, &lcd_class);

0 commit comments

Comments
 (0)