linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Markus Elfring <Markus.Elfring@web.de>,
	linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [V2 PATCH] usb: mtu3: fix NULL pointer dereference
Date: Wed, 1 Jul 2020 13:58:21 +0200	[thread overview]
Message-ID: <20200701115821.GA2184169@kroah.com> (raw)
In-Reply-To: <1593502942-24455-1-git-send-email-chunfeng.yun@mediatek.com>

On Tue, Jun 30, 2020 at 03:42:22PM +0800, Chunfeng Yun wrote:
> Some pointers are dereferenced before successful checks.
> 
> Reported-by: Markus Elfring <Markus.Elfring@web.de>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
> v2: nothing changed, but abandon another patch
> ---
>  drivers/usb/mtu3/mtu3_gadget.c | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
> index f93732e..1689ca8 100644
> --- a/drivers/usb/mtu3/mtu3_gadget.c
> +++ b/drivers/usb/mtu3/mtu3_gadget.c
> @@ -332,14 +332,21 @@ static int mtu3_gadget_queue(struct usb_ep *ep,
>  
>  static int mtu3_gadget_dequeue(struct usb_ep *ep, struct usb_request *req)
>  {
> -	struct mtu3_ep *mep = to_mtu3_ep(ep);
> -	struct mtu3_request *mreq = to_mtu3_request(req);
> +	struct mtu3_ep *mep;
> +	struct mtu3_request *mreq;
>  	struct mtu3_request *r;
> +	struct mtu3 *mtu;
>  	unsigned long flags;
>  	int ret = 0;
> -	struct mtu3 *mtu = mep->mtu;
>  
> -	if (!ep || !req || mreq->mep != mep)
> +	if (!ep || !req)
> +		return -EINVAL;

How will either of those ever be NULL?  The kernel will not call this
function with either of them being NULL, right?

> +
> +	mep = to_mtu3_ep(ep);
> +	mtu = mep->mtu;
> +
> +	mreq = to_mtu3_request(req);
> +	if (mreq->mep != mep)
>  		return -EINVAL;
>  
>  	dev_dbg(mtu->dev, "%s : req=%p\n", __func__, req);
> @@ -373,8 +380,8 @@ static int mtu3_gadget_dequeue(struct usb_ep *ep, struct usb_request *req)
>   */
>  static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)
>  {
> -	struct mtu3_ep *mep = to_mtu3_ep(ep);
> -	struct mtu3 *mtu = mep->mtu;
> +	struct mtu3_ep *mep;
> +	struct mtu3 *mtu;
>  	struct mtu3_request *mreq;
>  	unsigned long flags;
>  	int ret = 0;
> @@ -382,6 +389,9 @@ static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)
>  	if (!ep)
>  		return -EINVAL;

Same here, how can that ever happen?

>  
> +	mep = to_mtu3_ep(ep);
> +	mtu = mep->mtu;
> +
>  	dev_dbg(mtu->dev, "%s : %s...", __func__, ep->name);
>  
>  	spin_lock_irqsave(&mtu->lock, flags);
> @@ -422,11 +432,12 @@ static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)
>  /* Sets the halt feature with the clear requests ignored */
>  static int mtu3_gadget_ep_set_wedge(struct usb_ep *ep)
>  {
> -	struct mtu3_ep *mep = to_mtu3_ep(ep);
> +	struct mtu3_ep *mep;
>  
>  	if (!ep)
>  		return -EINVAL;

Again, same here.

thanks,

greg k-h

  parent reply	other threads:[~2020-07-01 11:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30  7:42 [V2 PATCH] usb: mtu3: fix NULL pointer dereference Chunfeng Yun
2020-06-30 10:47 ` [PATCH v2] usb: mtu3: Fix NULL pointer dereferences Markus Elfring
2020-07-01 11:58 ` Greg Kroah-Hartman [this message]
2020-07-02  2:52   ` [V2 PATCH] usb: mtu3: fix NULL pointer dereference Chunfeng Yun
2020-07-09  6:42     ` Felipe Balbi
2020-07-09  6:40 ` Felipe Balbi
2020-07-09  7:05   ` Chunfeng Yun

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=20200701115821.GA2184169@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=Markus.Elfring@web.de \
    --cc=chunfeng.yun@mediatek.com \
    --cc=felipe.balbi@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).