All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>, Bin Liu <b-liu@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] usb: musb: gadget: misplaced out of bounds check
Date: Tue, 20 Mar 2018 12:36:30 +0300	[thread overview]
Message-ID: <51c311a2-45d9-03d5-a294-dd77c80c0fb0@cogentembedded.com> (raw)
In-Reply-To: <20180320022735.4548-1-xypron.glpk@gmx.de>

Hello!

On 3/20/2018 5:27 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
> 	Only the 4 low bits of epnum are relevant for indexing.	
> ---
>   drivers/usb/musb/musb_gadget_ep0.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
> index 18da4873e52e..96b0fa12f729 100644
> --- a/drivers/usb/musb/musb_gadget_ep0.c
> +++ b/drivers/usb/musb/musb_gadget_ep0.c
> @@ -89,15 +89,20 @@ static int service_tx_status_request(
>   		}
>   
>   		is_in = epnum & USB_DIR_IN;
> +		epnum &= 0x0f;
> +		if (epnum >= MUSB_C_NUM_EPS) {
> +			handled = -EINVAL;
> +			break;
> +		}
> +
>   		if (is_in) {
> -			epnum &= 0x0f;
>   			ep = &musb->endpoints[epnum].ep_in;
>   		} else {
>   			ep = &musb->endpoints[epnum].ep_out;
>   		}

    Please remove the braces, they're not needed anymore.

[...]

MBR, Sergei

WARNING: multiple messages have this Message-ID (diff)
From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>, Bin Liu <b-liu@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [v2,1/1] usb: musb: gadget: misplaced out of bounds check
Date: Tue, 20 Mar 2018 12:36:30 +0300	[thread overview]
Message-ID: <51c311a2-45d9-03d5-a294-dd77c80c0fb0@cogentembedded.com> (raw)

Hello!

On 3/20/2018 5:27 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
> 	Only the 4 low bits of epnum are relevant for indexing.	
> ---
>   drivers/usb/musb/musb_gadget_ep0.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
> index 18da4873e52e..96b0fa12f729 100644
> --- a/drivers/usb/musb/musb_gadget_ep0.c
> +++ b/drivers/usb/musb/musb_gadget_ep0.c
> @@ -89,15 +89,20 @@ static int service_tx_status_request(
>   		}
>   
>   		is_in = epnum & USB_DIR_IN;
> +		epnum &= 0x0f;
> +		if (epnum >= MUSB_C_NUM_EPS) {
> +			handled = -EINVAL;
> +			break;
> +		}
> +
>   		if (is_in) {
> -			epnum &= 0x0f;
>   			ep = &musb->endpoints[epnum].ep_in;
>   		} else {
>   			ep = &musb->endpoints[epnum].ep_out;
>   		}

    Please remove the braces, they're not needed anymore.

[...]

MBR, Sergei
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-03-20  9:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20  2:27 [PATCH v2 1/1] usb: musb: gadget: misplaced out of bounds check Heinrich Schuchardt
2018-03-20  2:27 ` [v2,1/1] " Heinrich Schuchardt
2018-03-20  9:36 ` Sergei Shtylyov [this message]
2018-03-20  9:36   ` Sergei Shtylyov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51c311a2-45d9-03d5-a294-dd77c80c0fb0@cogentembedded.com \
    --to=sergei.shtylyov@cogentembedded.com \
    --cc=b-liu@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.