usb: usbip tool: Check the return of get_nports()
authorYuyang Du <yuyang.du@intel.com>
Mon, 22 May 2017 10:20:15 +0000 (18:20 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Jun 2017 08:48:24 +0000 (10:48 +0200)
If we get nonpositive number of ports, there is no sense to
continue, then fail gracefully.

In addition, the commit 0775a9cbc694e8c72 ("usbip: vhci extension:
modifications to vhci driver") introduced configurable numbers of
controllers and ports, but we have a static port number maximum,
MAXNPORT. If exceeded, the idev array will be overflown. We fix
it by validating the nports to make sure the port number max is
not exceeded.

Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Yuyang Du <yuyang.du@intel.com>
Acked-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/usbip/libsrc/vhci_driver.c

index f659c146cdc8410001a3da7197f2a47566e63a35..036b62be0fc71f9c16a99aa398a5c95202c6665e 100644 (file)
@@ -220,9 +220,16 @@ int usbip_vhci_driver_open(void)
        }
 
        vhci_driver->nports = get_nports();
-
        dbg("available ports: %d", vhci_driver->nports);
 
+       if (vhci_driver->nports <= 0) {
+               err("no available ports");
+               goto err;
+       } else if (vhci_driver->nports > MAXNPORT) {
+               err("port number exceeds %d", MAXNPORT);
+               goto err;
+       }
+
        if (refresh_imported_device_list())
                goto err;