USB: hub: Avoid NULL pointer dereference when hub doesn't have any ports
authorDavid Linares <dlinares.linux@gmail.com>
Mon, 25 Mar 2013 10:50:27 +0000 (10:50 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Mar 2013 17:57:37 +0000 (10:57 -0700)
commit769d7368b1727b1b5369d88badf0cbdf0163e079
tree29fabb4a85ce78d944ac28154b63c71f57ad4cdd
parent5410a473fb7a466020af31e8b400c2d14ed94925
USB: hub: Avoid NULL pointer dereference when hub doesn't have any ports

Return an error if hub->descriptor->bNbrPorts==0. Without this additional
check, we can end up doing a "hub->ports = kzalloc(0, GFP_KERNEL)".
This hub->ports pointer will therefore be non-NULL and will be used.
Example of dmesg:
   INIT: usb 1-1: New USB device found, idVendor=0424, idProduct=2512
   usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
   hub 1-1:1.0: USB hub found
   version 2.86 bootinghub 1-1:1.0: 0 ports detected
   Unable to handle kernel NULL pointer dereference at virtual address 00000010

Signed-off-by: David Linares <dlinares.linux@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/hub.c