public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: cdns2: fix possible null-ptr-deref in cdns2_gadget_ep_queue()
@ 2024-10-28  3:50 Yi Yang
  2024-10-29  3:36 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Yang @ 2024-10-28  3:50 UTC (permalink / raw)
  To: pawell, gregkh; +Cc: linux-usb, wangweiyang2

The cdns2_gadget_ep_alloc_request() will return NULL when kzalloc() fails,
fix possible null-ptr-deref by check return value.

Fixes: 3eb1f1efe204 ("usb: cdns2: Add main part of Cadence USBHS driver")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/usb/gadget/udc/cdns2/cdns2-gadget.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
index 62fce42ef2da..c06a50af268e 100644
--- a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
+++ b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
@@ -1724,6 +1724,10 @@ static int cdns2_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
 		struct cdns2_request *preq;
 
 		zlp_request = cdns2_gadget_ep_alloc_request(ep, GFP_ATOMIC);
+		if (!zlp_request) {
+			spin_unlock_irqrestore(&pdev->lock, flags);
+			return -ENOMEM;
+		}
 		zlp_request->buf = pdev->zlp_buf;
 		zlp_request->length = 0;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: cdns2: fix possible null-ptr-deref in cdns2_gadget_ep_queue()
  2024-10-28  3:50 [PATCH] usb: cdns2: fix possible null-ptr-deref in cdns2_gadget_ep_queue() Yi Yang
@ 2024-10-29  3:36 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2024-10-29  3:36 UTC (permalink / raw)
  To: Yi Yang; +Cc: pawell, linux-usb, wangweiyang2

On Mon, Oct 28, 2024 at 03:50:28AM +0000, Yi Yang wrote:
> The cdns2_gadget_ep_alloc_request() will return NULL when kzalloc() fails,
> fix possible null-ptr-deref by check return value.
> 
> Fixes: 3eb1f1efe204 ("usb: cdns2: Add main part of Cadence USBHS driver")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  drivers/usb/gadget/udc/cdns2/cdns2-gadget.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
> index 62fce42ef2da..c06a50af268e 100644
> --- a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
> +++ b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
> @@ -1724,6 +1724,10 @@ static int cdns2_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
>  		struct cdns2_request *preq;
>  
>  		zlp_request = cdns2_gadget_ep_alloc_request(ep, GFP_ATOMIC);
> +		if (!zlp_request) {
> +			spin_unlock_irqrestore(&pdev->lock, flags);
> +			return -ENOMEM;
> +		}
>  		zlp_request->buf = pdev->zlp_buf;
>  		zlp_request->length = 0;
>  
> -- 
> 2.25.1
> 
> 

How was this tested to verify it works properly?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-29  3:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28  3:50 [PATCH] usb: cdns2: fix possible null-ptr-deref in cdns2_gadget_ep_queue() Yi Yang
2024-10-29  3:36 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox