* [V2 PATCH] usb: mtu3: fix NULL pointer dereference
@ 2020-06-30 7:42 Chunfeng Yun
2020-06-30 10:47 ` [PATCH v2] usb: mtu3: Fix NULL pointer dereferences Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Chunfeng Yun @ 2020-06-30 7:42 UTC (permalink / raw)
To: Greg Kroah-Hartman, Felipe Balbi
Cc: Matthias Brugger, Markus Elfring, Chunfeng Yun, linux-usb,
linux-arm-kernel, linux-mediatek, linux-kernel
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;
+
+ 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;
+ 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;
+ mep = to_mtu3_ep(ep);
mep->wedged = 1;
return usb_ep_set_halt(ep);
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] usb: mtu3: Fix NULL pointer dereferences
2020-06-30 7:42 [V2 PATCH] usb: mtu3: fix NULL pointer dereference Chunfeng Yun
@ 2020-06-30 10:47 ` Markus Elfring
2020-07-01 11:58 ` [V2 PATCH] usb: mtu3: fix NULL pointer dereference Greg Kroah-Hartman
2020-07-09 6:40 ` Felipe Balbi
2 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-06-30 10:47 UTC (permalink / raw)
To: Chunfeng Yun, Greg Kroah-Hartman, Matthias Brugger, linux-usb,
linux-arm-kernel, linux-mediatek
Cc: linux-kernel, kernel-janitors, Colin Ian King
> Some pointers are dereferenced before successful checks.
I propose to reconsider and improve also this change description.
* Would a null pointer dereference be possible only with the variables “mep”
and “mreq” in the implementation of the function “mtu3_gadget_dequeue”?
(Can it make sense to split the patch according to this detail?)
* How do you think about to convert any more variable initialisations
to later assignments?
* Will it become helpful to add the tag “Fixes” to the commit message?
…
> ---
> v2: nothing changed, but abandon another patch
Are there chances to take any previous patch review comments better into account
(besides the shown reduction of update steps)?
> ---
> drivers/usb/mtu3/mtu3_gadget.c | 25 ++++++++++++++++++-------
I suggest to replace the triple dashes before this diffstat by a blank line.
Regards,
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [V2 PATCH] usb: mtu3: fix NULL pointer dereference
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
2020-07-02 2:52 ` Chunfeng Yun
2020-07-09 6:40 ` Felipe Balbi
2 siblings, 1 reply; 7+ messages in thread
From: Greg Kroah-Hartman @ 2020-07-01 11:58 UTC (permalink / raw)
To: Chunfeng Yun
Cc: Felipe Balbi, Matthias Brugger, Markus Elfring, linux-usb,
linux-arm-kernel, linux-mediatek, linux-kernel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [V2 PATCH] usb: mtu3: fix NULL pointer dereference
2020-07-01 11:58 ` [V2 PATCH] usb: mtu3: fix NULL pointer dereference Greg Kroah-Hartman
@ 2020-07-02 2:52 ` Chunfeng Yun
2020-07-09 6:42 ` Felipe Balbi
0 siblings, 1 reply; 7+ messages in thread
From: Chunfeng Yun @ 2020-07-02 2:52 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Matthias Brugger, Markus Elfring, linux-usb,
linux-arm-kernel, linux-mediatek, linux-kernel
On Wed, 2020-07-01 at 13:58 +0200, Greg Kroah-Hartman wrote:
> 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?
Yes, I find all class drivers already ensure they are not NULL.
>
> > +
> > + 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?
Maybe when the class driver has something wrong:)
You mean it's better to remove these unnecessary checks?
Thanks
>
> >
> > + 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [V2 PATCH] usb: mtu3: fix NULL pointer dereference
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 ` [V2 PATCH] usb: mtu3: fix NULL pointer dereference Greg Kroah-Hartman
@ 2020-07-09 6:40 ` Felipe Balbi
2020-07-09 7:05 ` Chunfeng Yun
2 siblings, 1 reply; 7+ messages in thread
From: Felipe Balbi @ 2020-07-09 6:40 UTC (permalink / raw)
To: Chunfeng Yun, Greg Kroah-Hartman, Felipe Balbi
Cc: Matthias Brugger, Markus Elfring, Chunfeng Yun, linux-usb,
linux-arm-kernel, linux-mediatek, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 301 bytes --]
Chunfeng Yun <chunfeng.yun@mediatek.com> writes:
> Some pointers are dereferenced before successful checks.
>
> Reported-by: Markus Elfring <Markus.Elfring@web.de>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
do you need a Fixes tag here? Perhaps a Cc stable too?
--
balbi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [V2 PATCH] usb: mtu3: fix NULL pointer dereference
2020-07-02 2:52 ` Chunfeng Yun
@ 2020-07-09 6:42 ` Felipe Balbi
0 siblings, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2020-07-09 6:42 UTC (permalink / raw)
To: Chunfeng Yun, Greg Kroah-Hartman
Cc: Felipe Balbi, Matthias Brugger, Markus Elfring, linux-usb,
linux-arm-kernel, linux-mediatek, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 952 bytes --]
Hi,
Chunfeng Yun <chunfeng.yun@mediatek.com> writes:
>> > @@ -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?
> Maybe when the class driver has something wrong:)
>
> You mean it's better to remove these unnecessary checks?
if we need those checks, I'd rather have them at a central location,
such as udc/core.c. But, as Greg mentioned, the kernel doesn't call
these with NULL pointers.
--
balbi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [V2 PATCH] usb: mtu3: fix NULL pointer dereference
2020-07-09 6:40 ` Felipe Balbi
@ 2020-07-09 7:05 ` Chunfeng Yun
0 siblings, 0 replies; 7+ messages in thread
From: Chunfeng Yun @ 2020-07-09 7:05 UTC (permalink / raw)
To: Felipe Balbi
Cc: Greg Kroah-Hartman, Felipe Balbi, Matthias Brugger,
Markus Elfring, linux-usb, linux-arm-kernel, linux-mediatek,
linux-kernel
On Thu, 2020-07-09 at 09:40 +0300, Felipe Balbi wrote:
> Chunfeng Yun <chunfeng.yun@mediatek.com> writes:
>
> > Some pointers are dereferenced before successful checks.
> >
> > Reported-by: Markus Elfring <Markus.Elfring@web.de>
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
>
> do you need a Fixes tag here? Perhaps a Cc stable too?
It will not cause somes issues, I think no need add it.
According to Greg's comment, I guess he means no need check these
pointers at all, so I'll send a new version to remove checks.
Thank you
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-07-09 7:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [V2 PATCH] usb: mtu3: fix NULL pointer dereference Greg Kroah-Hartman
2020-07-02 2:52 ` Chunfeng Yun
2020-07-09 6:42 ` Felipe Balbi
2020-07-09 6:40 ` Felipe Balbi
2020-07-09 7:05 ` Chunfeng Yun
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).