]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
usb: musb: gadget: misplaced out of bounds check
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Thu, 29 Mar 2018 15:48:28 +0000 (10:48 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Mar 2018 16:37:28 +0000 (18:37 +0200)
musb->endpoints[] has array size MUSB_C_NUM_EPS.
We must check array bounds before accessing the array and not afterwards.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Bin Liu <b-liu@ti.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/musb/musb_gadget_ep0.c

index 18da4873e52e0c3f10097f6026049839716ef783..91a5027b5c1f97d522c7beed568f2ac39e74ea86 100644 (file)
@@ -89,15 +89,19 @@ static int service_tx_status_request(
                }
 
                is_in = epnum & USB_DIR_IN;
-               if (is_in) {
-                       epnum &= 0x0f;
+               epnum &= 0x0f;
+               if (epnum >= MUSB_C_NUM_EPS) {
+                       handled = -EINVAL;
+                       break;
+               }
+
+               if (is_in)
                        ep = &musb->endpoints[epnum].ep_in;
-               } else {
+               else
                        ep = &musb->endpoints[epnum].ep_out;
-               }
                regs = musb->endpoints[epnum].regs;
 
-               if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
+               if (!ep->desc) {
                        handled = -EINVAL;
                        break;
                }