Skip to contentSkip to conversation

handle usb host allocation failures

PATCH Applied Jesse Barnes 2 participants 2 messages Sep 27, 2004 – Sep 29, 2004 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 handle usb host allocation failures

It looks like a host (like ohci or whatever) could try to allocate a new usb_device structure with usb_alloc_dev and get back a valid pointer even if the allocation of its private data failed. I first saw this in the 2.4 sources, but it looks like 2.6 has the same problem. This patch attempts to fix it by freeing dev if the ->allocate() routine fails, and then returns NULL instead of a potentially dangerous dev pointer.

Thanks,
Jesse

===== drivers/usb/core/usb.c 1.174 vs edited =====

drivers/usb/core/usb.c +4 -1
@@ -759,7 +759,10 @@
 	init_MUTEX(&dev->serialize);
 
 	if (dev->bus->op->allocate)
-		dev->bus->op->allocate(dev);
+		if (dev->bus->op->allocate(dev)) {
+			kfree(dev);
+			return NULL;
+		}
 
 	return dev;
 }
Applied
#1 lore raw
Quoted 8 lines · Jesse Barnes

It looks like a host (like ohci or whatever) could try to allocate a new usb_device structure with usb_alloc_dev and get back a valid pointer even if the allocation of its private data failed. I first saw this in the 2.4 sources, but it looks like 2.6 has the same problem. This patch attempts to fix it by freeing dev if the ->allocate() routine fails, and then returns NULL instead of a potentially dangerous dev pointer.

Applied, thanks.

greg k-h