* [PATCH 1/1] usb: musb: gadget: misplaced out of bounds check
@ 2018-03-19 7:12 Heinrich Schuchardt
2018-03-19 16:26 ` Bin Liu
0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2018-03-19 7:12 UTC (permalink / raw)
To: Bin Liu; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Heinrich Schuchardt
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/musb_gadget_ep0.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 18da4873e52e..482e7c2f8dc7 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -88,6 +88,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;
@@ -97,7 +102,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] 2+ messages in thread* Re: [PATCH 1/1] usb: musb: gadget: misplaced out of bounds check
2018-03-19 7:12 [PATCH 1/1] usb: musb: gadget: misplaced out of bounds check Heinrich Schuchardt
@ 2018-03-19 16:26 ` Bin Liu
0 siblings, 0 replies; 2+ messages in thread
From: Bin Liu @ 2018-03-19 16:26 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel
Hi,
On Mon, Mar 19, 2018 at 08:12:28AM +0100, 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>
> ---
> drivers/usb/musb/musb_gadget_ep0.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
> index 18da4873e52e..482e7c2f8dc7 100644
> --- a/drivers/usb/musb/musb_gadget_ep0.c
> +++ b/drivers/usb/musb/musb_gadget_ep0.c
> @@ -88,6 +88,11 @@ static int service_tx_status_request(
> break;
> }
>
> + if (epnum >= MUSB_C_NUM_EPS) {
only the LSB 4 bits are the EP number, bit7 is the direction flag. So
you can only compare the LSB 4 bits here.
Regards,
-Bin.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-19 16:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-19 7:12 [PATCH 1/1] usb: musb: gadget: misplaced out of bounds check Heinrich Schuchardt
2018-03-19 16:26 ` Bin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox