* [PATCH v2] usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()
@ 2022-07-18 16:00 Andrey Strachuk
2022-07-27 8:39 ` Peter Chen
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Strachuk @ 2022-07-18 16:00 UTC (permalink / raw)
To: Peter Chen
Cc: Andrey Strachuk, Pawel Laszczak, Roger Quadros,
Aswath Govindraju, Greg Kroah-Hartman, linux-usb, linux-kernel,
ldv-project
If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid pointer
and its dereference with priv_ep->cdns3_dev may cause panic.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Andrey Strachuk <strochuk@ispras.ru>
Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
---
drivers/usb/cdns3/cdns3-gadget.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
index 5c15c48952a6..aea5db0ec72d 100644
--- a/drivers/usb/cdns3/cdns3-gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -2285,13 +2285,14 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,
int val;
priv_ep = ep_to_cdns3_ep(ep);
- priv_dev = priv_ep->cdns3_dev;
- comp_desc = priv_ep->endpoint.comp_desc;
if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
dev_dbg(priv_dev->dev, "usbss: invalid parameters\n");
return -EINVAL;
}
+
+ comp_desc = priv_ep->endpoint.comp_desc;
+ priv_dev = priv_ep->cdns3_dev;
if (!desc->wMaxPacketSize) {
dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n");
@@ -2600,7 +2601,7 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
struct usb_request *request)
{
struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep);
- struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
+ struct cdns3_device *priv_dev;
struct usb_request *req, *req_temp;
struct cdns3_request *priv_req;
struct cdns3_trb *link_trb;
@@ -2610,6 +2611,8 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
if (!ep || !request || !ep->desc)
return -EINVAL;
+
+ priv_dev = priv_ep->cdns3_dev;
spin_lock_irqsave(&priv_dev->lock, flags);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()
2022-07-18 16:00 [PATCH v2] usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable() Andrey Strachuk
@ 2022-07-27 8:39 ` Peter Chen
2022-07-27 9:03 ` [ldv-project] " Alexey Khoroshilov
0 siblings, 1 reply; 3+ messages in thread
From: Peter Chen @ 2022-07-27 8:39 UTC (permalink / raw)
To: Andrey Strachuk
Cc: Pawel Laszczak, Roger Quadros, Aswath Govindraju,
Greg Kroah-Hartman, linux-usb, linux-kernel, ldv-project
On 22-07-18 19:00:52, Andrey Strachuk wrote:
> If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid pointer
> and its dereference with priv_ep->cdns3_dev may cause panic.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Andrey Strachuk <strochuk@ispras.ru>
> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
> ---
> drivers/usb/cdns3/cdns3-gadget.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
> index 5c15c48952a6..aea5db0ec72d 100644
> --- a/drivers/usb/cdns3/cdns3-gadget.c
> +++ b/drivers/usb/cdns3/cdns3-gadget.c
> @@ -2285,13 +2285,14 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,
> int val;
>
> priv_ep = ep_to_cdns3_ep(ep);
> - priv_dev = priv_ep->cdns3_dev;
> - comp_desc = priv_ep->endpoint.comp_desc;
>
> if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
> dev_dbg(priv_dev->dev, "usbss: invalid parameters\n");
> return -EINVAL;
> }
> +
> + comp_desc = priv_ep->endpoint.comp_desc;
> + priv_dev = priv_ep->cdns3_dev;
>
> if (!desc->wMaxPacketSize) {
> dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n");
> @@ -2600,7 +2601,7 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
> struct usb_request *request)
> {
> struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep);
> - struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
> + struct cdns3_device *priv_dev;
> struct usb_request *req, *req_temp;
> struct cdns3_request *priv_req;
> struct cdns3_trb *link_trb;
> @@ -2610,6 +2611,8 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
>
> if (!ep || !request || !ep->desc)
> return -EINVAL;
> +
> + priv_dev = priv_ep->cdns3_dev;
>
> spin_lock_irqsave(&priv_dev->lock, flags);
>
> --
Acked-by: Peter Chen <peter.chen@kernel.org>
--
Thanks,
Peter Chen
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ldv-project] [PATCH v2] usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()
2022-07-27 8:39 ` Peter Chen
@ 2022-07-27 9:03 ` Alexey Khoroshilov
0 siblings, 0 replies; 3+ messages in thread
From: Alexey Khoroshilov @ 2022-07-27 9:03 UTC (permalink / raw)
To: Peter Chen, Andrey Strachuk
Cc: ldv-project, Pawel Laszczak, Greg Kroah-Hartman, linux-usb,
linux-kernel, Roger Quadros, Aswath Govindraju
On 27.07.2022 11:39, Peter Chen wrote:
> On 22-07-18 19:00:52, Andrey Strachuk wrote:
>> If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid pointer
>> and its dereference with priv_ep->cdns3_dev may cause panic.
>>
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Signed-off-by: Andrey Strachuk <strochuk@ispras.ru>
>> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
>> ---
>> drivers/usb/cdns3/cdns3-gadget.c | 9 ++++++---
>> 1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
>> index 5c15c48952a6..aea5db0ec72d 100644
>> --- a/drivers/usb/cdns3/cdns3-gadget.c
>> +++ b/drivers/usb/cdns3/cdns3-gadget.c
>> @@ -2285,13 +2285,14 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,
>> int val;
>>
>> priv_ep = ep_to_cdns3_ep(ep);
>> - priv_dev = priv_ep->cdns3_dev;
>> - comp_desc = priv_ep->endpoint.comp_desc;
>>
>> if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
>> dev_dbg(priv_dev->dev, "usbss: invalid parameters\n");
>> return -EINVAL;
>> }
>> +
>> + comp_desc = priv_ep->endpoint.comp_desc;
>> + priv_dev = priv_ep->cdns3_dev;
>>
>> if (!desc->wMaxPacketSize) {
>> dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n");
>> @@ -2600,7 +2601,7 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
>> struct usb_request *request)
>> {
>> struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep);
>> - struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
>> + struct cdns3_device *priv_dev;
>> struct usb_request *req, *req_temp;
>> struct cdns3_request *priv_req;
>> struct cdns3_trb *link_trb;
>> @@ -2610,6 +2611,8 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
>>
>> if (!ep || !request || !ep->desc)
>> return -EINVAL;
>> +
>> + priv_dev = priv_ep->cdns3_dev;
>>
>> spin_lock_irqsave(&priv_dev->lock, flags);
>>
>> --
>
> Acked-by: Peter Chen <peter.chen@kernel.org>
>
Looks good, but I would suggest to move
priv_ep = ep_to_cdns3_ep(ep);
below the check of 'ep' as well.
--
Alexey
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-27 9:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 16:00 [PATCH v2] usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable() Andrey Strachuk
2022-07-27 8:39 ` Peter Chen
2022-07-27 9:03 ` [ldv-project] " Alexey Khoroshilov
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).