diff mbox

[v3,1/4] usb: renesas_usbhs: gadget: fix NULL pointer dereference in ep_disable()

Message ID 1414665019-1340-2-git-send-email-yoshihiro.shimoda.uh@renesas.com (mailing list archive)
State Superseded
Headers show

Commit Message

Yoshihiro Shimoda Oct. 30, 2014, 10:30 a.m. UTC
From: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>

This patch fixes an issue that the NULL pointer dereference happens
when we uses g_audio driver. Since the g_audio driver will call
usb_ep_disable() in afunc_set_alt() before it calls usb_ep_enable(),
the uep->pipe of renesas usbhs driver will be NULL. So, this patch
adds a condition to avoid the oops.

Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: <stable@vger.kernel.org>
---
 drivers/usb/renesas_usbhs/mod_gadget.c |    3 +++
 1 file changed, 3 insertions(+)

Comments

Felipe Balbi Oct. 30, 2014, 2:10 p.m. UTC | #1
On Thu, Oct 30, 2014 at 07:30:16PM +0900, Yoshihiro Shimoda wrote:
> From: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> 
> This patch fixes an issue that the NULL pointer dereference happens
> when we uses g_audio driver. Since the g_audio driver will call
> usb_ep_disable() in afunc_set_alt() before it calls usb_ep_enable(),
> the uep->pipe of renesas usbhs driver will be NULL. So, this patch
> adds a condition to avoid the oops.
> 
> Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Cc: <stable@vger.kernel.org>
> ---
>  drivers/usb/renesas_usbhs/mod_gadget.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
> index 2d17c10..2d0903f 100644
> --- a/drivers/usb/renesas_usbhs/mod_gadget.c
> +++ b/drivers/usb/renesas_usbhs/mod_gadget.c
> @@ -602,6 +602,9 @@ static int usbhsg_ep_disable(struct usb_ep *ep)
>  	struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
>  	struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
>  
> +	if (!uep || !uep->pipe)

how can uep ever be NULL ? Look at the definition of usbhsg_ep_to_uep():

	#define usbhsg_ep_to_uep(e)             container_of(e, struct usbhsg_uep, ep)

how can a container_of() ever return NULL ? What you should check if
"ep" (the argument to this function) being NULL.
Yoshihiro Shimoda Oct. 31, 2014, 12:06 a.m. UTC | #2
> On Thu, Oct 30, 2014 at 07:30:16PM +0900, Yoshihiro Shimoda wrote:
> > From: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> >
> > This patch fixes an issue that the NULL pointer dereference happens
> > when we uses g_audio driver. Since the g_audio driver will call
> > usb_ep_disable() in afunc_set_alt() before it calls usb_ep_enable(),
> > the uep->pipe of renesas usbhs driver will be NULL. So, this patch
> > adds a condition to avoid the oops.
> >
> > Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> > Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > Cc: <stable@vger.kernel.org>
> > ---
> >  drivers/usb/renesas_usbhs/mod_gadget.c |    3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c
> > b/drivers/usb/renesas_usbhs/mod_gadget.c
> > index 2d17c10..2d0903f 100644
> > --- a/drivers/usb/renesas_usbhs/mod_gadget.c
> > +++ b/drivers/usb/renesas_usbhs/mod_gadget.c
> > @@ -602,6 +602,9 @@ static int usbhsg_ep_disable(struct usb_ep *ep)
> >  	struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
> >  	struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
> >
> > +	if (!uep || !uep->pipe)
> 
> how can uep ever be NULL ? Look at the definition of usbhsg_ep_to_uep():
> 
> 	#define usbhsg_ep_to_uep(e)             container_of(e, struct usbhsg_uep, ep)
> 
> how can a container_of() ever return NULL ? What you should check if "ep" (the argument to this function) being NULL.

Thank you for the point.
Morimoto-san also pointed out this code at v1 patch. But I forgot to fix it...
We can change the "if (!uep || !uep->pipe)" to "if (!pipe)".

I will fix this patch.

Best regards,
Yoshihiro Shimoda

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Felipe Balbi Oct. 31, 2014, 12:48 a.m. UTC | #3
On Fri, Oct 31, 2014 at 12:06:06AM +0000, yoshihiro shimoda wrote:
> > On Thu, Oct 30, 2014 at 07:30:16PM +0900, Yoshihiro Shimoda wrote:
> > > From: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> > >
> > > This patch fixes an issue that the NULL pointer dereference happens
> > > when we uses g_audio driver. Since the g_audio driver will call
> > > usb_ep_disable() in afunc_set_alt() before it calls usb_ep_enable(),
> > > the uep->pipe of renesas usbhs driver will be NULL. So, this patch
> > > adds a condition to avoid the oops.
> > >
> > > Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> > > Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > Cc: <stable@vger.kernel.org>
> > > ---
> > >  drivers/usb/renesas_usbhs/mod_gadget.c |    3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c
> > > b/drivers/usb/renesas_usbhs/mod_gadget.c
> > > index 2d17c10..2d0903f 100644
> > > --- a/drivers/usb/renesas_usbhs/mod_gadget.c
> > > +++ b/drivers/usb/renesas_usbhs/mod_gadget.c
> > > @@ -602,6 +602,9 @@ static int usbhsg_ep_disable(struct usb_ep *ep)
> > >  	struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
> > >  	struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
> > >
> > > +	if (!uep || !uep->pipe)
> > 
> > how can uep ever be NULL ? Look at the definition of
> > usbhsg_ep_to_uep():
> > 
> > 	#define usbhsg_ep_to_uep(e)             container_of(e, struct usbhsg_uep, ep)
> > 
> > how can a container_of() ever return NULL ? What you should check if
> > "ep" (the argument to this function) being NULL.
> 
> Thank you for the point.
> Morimoto-san also pointed out this code at v1 patch. But I forgot to fix it...
> We can change the "if (!uep || !uep->pipe)" to "if (!pipe)".

alright, I'll wait for a new version. Thank you
diff mbox

Patch

diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 2d17c10..2d0903f 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -602,6 +602,9 @@  static int usbhsg_ep_disable(struct usb_ep *ep)
 	struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
 	struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
 
+	if (!uep || !uep->pipe)
+		return -EINVAL;
+
 	usbhsg_pipe_disable(uep);
 	usbhs_pipe_free(pipe);