Skip to contentSkip to conversation

USB: usb_driver_claim_interface: add sanity checking

PATCH In review Lu Baolu 1 participant 6 messages Mar 25, 2016

Subsystems (5)
lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/10 USB: usb_driver_claim_interface: add sanity checking

From: Oliver Neukum <[email protected]>

Attacks that trick drivers into passing a NULL pointer to usb_driver_claim_interface() using forged descriptors are known. This thwarts them by sanity checking.

---
 drivers/usb/core/driver.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/core/driver.c +5 -1
index 56593a9..2057d91 100644
@@ -502,11 +502,15 @@ static int usb_unbind_interface(struct device *dev)
 int usb_driver_claim_interface(struct usb_driver *driver,
 				struct usb_interface *iface, void *priv)
 {
-	struct device *dev = &iface->dev;
+	struct device *dev;
 	struct usb_device *udev;
 	int retval = 0;
 	int lpm_disable_error;
 
+	if (!iface)
+		return -ENODEV;
+
+	dev = &iface->dev;
 	if (dev->driver)
 		return -EBUSY;
 
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH 2/10 USB: cdc-acm: more sanity checking

From: Oliver Neukum <[email protected]>

An attack has become available which pretends to be a quirky device circumventing normal sanity checks and crashes the kernel by an insufficient number of interfaces. This patch adds a check to the code path for quirky devices.

---
 drivers/usb/class/cdc-acm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/class/cdc-acm.c +3 -0
index 1d2c99a..83fd30b 100644
@@ -1179,6 +1179,9 @@ static int acm_probe(struct usb_interface *intf,
 	if (quirks == NO_UNION_NORMAL) {
 		data_interface = usb_ifnum_to_if(usb_dev, 1);
 		control_interface = usb_ifnum_to_if(usb_dev, 0);
+		/* we would crash */
+		if (!data_interface || !control_interface)
+			return -ENODEV;
 		goto skip_normal_probe;
 	}
 
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/10 USB: uas: Reduce can_queue to MAX_CMNDS

In reply to Lu Baolu

From: Hans de Goede <[email protected]>

The uas driver can never queue more then MAX_CMNDS (- 1) tags and tags are shared between luns, so there is no need to claim that we can_queue some random large number.

Not claiming that we can_queue 65536 commands, fixes the uas driver failing to initialize while allocating the tag map with a "Page allocation failure (order 7)" error on systems which have been running for a while and thus have fragmented memory.

---
 drivers/usb/storage/uas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/storage/uas.c +1 -1
index 44b096c..13e4cc3 100644
@@ -836,7 +836,7 @@ static struct scsi_host_template uas_host_template = {
 	.slave_configure = uas_slave_configure,
 	.eh_abort_handler = uas_eh_abort_handler,
 	.eh_bus_reset_handler = uas_eh_bus_reset_handler,
-	.can_queue = 65536,	/* Is there a limit on the _host_ ? */
+	.can_queue = MAX_CMNDS,
 	.this_id = -1,
 	.sg_tablesize = SG_NONE,
 	.skip_settle_delay = 1,
Signature · 1 line
2.1.4
author
#5 lore raw
In reply to Lu Baolu

I am sorry. This email was sent out due to an incorrect operation. Please ignore it. I am sorry for disturbing you.

Best regards,
Baolu

Quoted 34 lines · Lu Baolu

From: Oliver Neukum <[email protected]>

Attacks that trick drivers into passing a NULL pointer to usb_driver_claim_interface() using forged descriptors are known. This thwarts them by sanity checking.

---
 drivers/usb/core/driver.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/core/driver.c +5 -1
index 56593a9..2057d91 100644
@@ -502,11 +502,15 @@ static int usb_unbind_interface(struct device *dev)
 int usb_driver_claim_interface(struct usb_driver *driver,
 				struct usb_interface *iface, void *priv)
 {
-	struct device *dev = &iface->dev;
+	struct device *dev;
 	struct usb_device *udev;
 	int retval = 0;
 	int lpm_disable_error;
 
+	if (!iface)
+		return -ENODEV;
+
+	dev = &iface->dev;
 	if (dev->driver)
 		return -EBUSY;
 
author
#2 lore raw

Re: [PATCH 02/10] USB: cdc-acm: more sanity checking

In reply to Lu Baolu

I am sorry. This email was sent out due to an incorrect operation. Please ignore it. I am sorry for disturbing you.

Best regards,
Baolu

Quoted 28 lines · Lu Baolu

From: Oliver Neukum <[email protected]>

An attack has become available which pretends to be a quirky device circumventing normal sanity checks and crashes the kernel by an insufficient number of interfaces. This patch adds a check to the code path for quirky devices.

---
 drivers/usb/class/cdc-acm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/class/cdc-acm.c +3 -0
index 1d2c99a..83fd30b 100644
@@ -1179,6 +1179,9 @@ static int acm_probe(struct usb_interface *intf,
 	if (quirks == NO_UNION_NORMAL) {
 		data_interface = usb_ifnum_to_if(usb_dev, 1);
 		control_interface = usb_ifnum_to_if(usb_dev, 0);
+		/* we would crash */
+		if (!data_interface || !control_interface)
+			return -ENODEV;
 		goto skip_normal_probe;
 	}
 
author
#4 lore raw

Re: [PATCH 03/10] USB: uas: Reduce can_queue to MAX_CMNDS

In reply to Lu Baolu

I am sorry. This email was sent out due to an incorrect operation. Please ignore it. I am sorry for disturbing you.

Best Regards,
Baolu

Quoted 32 lines · Lu Baolu

From: Hans de Goede <[email protected]>

The uas driver can never queue more then MAX_CMNDS (- 1) tags and tags are shared between luns, so there is no need to claim that we can_queue some random large number.

Not claiming that we can_queue 65536 commands, fixes the uas driver failing to initialize while allocating the tag map with a "Page allocation failure (order 7)" error on systems which have been running for a while and thus have fragmented memory.

---
 drivers/usb/storage/uas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/storage/uas.c +1 -1
index 44b096c..13e4cc3 100644
@@ -836,7 +836,7 @@ static struct scsi_host_template uas_host_template = {
 	.slave_configure = uas_slave_configure,
 	.eh_abort_handler = uas_eh_abort_handler,
 	.eh_bus_reset_handler = uas_eh_bus_reset_handler,
-	.can_queue = 65536,	/* Is there a limit on the _host_ ? */
+	.can_queue = MAX_CMNDS,
 	.this_id = -1,
 	.sg_tablesize = SG_NONE,
 	.skip_settle_delay = 1,