All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/1] usb: musb-new: misplaced out of bounds check
@ 2018-03-18 13:18 Heinrich Schuchardt
  2018-03-19  6:50 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
  0 siblings, 1 reply; 3+ messages in thread
From: Heinrich Schuchardt @ 2018-03-18 13:18 UTC (permalink / raw)
  To: u-boot

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>
---
 drivers/usb/musb-new/musb_gadget_ep0.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb-new/musb_gadget_ep0.c b/drivers/usb/musb-new/musb_gadget_ep0.c
index 3cfcb2205a..7a249e55a1 100644
--- a/drivers/usb/musb-new/musb_gadget_ep0.c
+++ b/drivers/usb/musb-new/musb_gadget_ep0.c
@@ -95,6 +95,11 @@ static int service_tx_status_request(
 			break;
 		}
 
+		if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
+			handled = -EINVAL;
+			break;
+		}
+
 		is_in = epnum & USB_DIR_IN;
 		if (is_in) {
 			epnum &= 0x0f;
@@ -104,11 +109,6 @@ static int service_tx_status_request(
 		}
 		regs = musb->endpoints[epnum].regs;
 
-		if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
-			handled = -EINVAL;
-			break;
-		}
-
 		musb_ep_select(mbase, epnum);
 		if (is_in)
 			tmp = musb_readw(regs, MUSB_TXCSR)
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2 1/1] usb: musb-new: misplaced out of bounds check
  2018-03-18 13:18 [U-Boot] [PATCH 1/1] usb: musb-new: misplaced out of bounds check Heinrich Schuchardt
@ 2018-03-19  6:50 ` Heinrich Schuchardt
  2018-03-19  7:13   ` Heinrich Schuchardt
  0 siblings, 1 reply; 3+ messages in thread
From: Heinrich Schuchardt @ 2018-03-19  6:50 UTC (permalink / raw)
  To: u-boot

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>
---
v2
	do not move the ep->desc check
---
 drivers/usb/musb-new/musb_gadget_ep0.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb-new/musb_gadget_ep0.c b/drivers/usb/musb-new/musb_gadget_ep0.c
index 3cfcb2205a..aa57a7767d 100644
--- a/drivers/usb/musb-new/musb_gadget_ep0.c
+++ b/drivers/usb/musb-new/musb_gadget_ep0.c
@@ -95,6 +95,11 @@ static int service_tx_status_request(
 			break;
 		}
 
+		if (epnum >= MUSB_C_NUM_EPS) {
+			handled = -EINVAL;
+			break;
+		}
+
 		is_in = epnum & USB_DIR_IN;
 		if (is_in) {
 			epnum &= 0x0f;
@@ -104,7 +109,7 @@ static int service_tx_status_request(
 		}
 		regs = musb->endpoints[epnum].regs;
 
-		if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
+		if (!ep->desc) {
 			handled = -EINVAL;
 			break;
 		}
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2 1/1] usb: musb-new: misplaced out of bounds check
  2018-03-19  6:50 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
@ 2018-03-19  7:13   ` Heinrich Schuchardt
  0 siblings, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2018-03-19  7:13 UTC (permalink / raw)
  To: u-boot

On 03/19/2018 07:50 AM, Heinrich Schuchardt wrote:
> 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>
> ---
> v2
> 	do not move the ep->desc check
> ---

Upstreamed as
https://lkml.org/lkml/2018/3/19/52

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-19  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18 13:18 [U-Boot] [PATCH 1/1] usb: musb-new: misplaced out of bounds check Heinrich Schuchardt
2018-03-19  6:50 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
2018-03-19  7:13   ` Heinrich Schuchardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.