All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: Fix double free of device descriptor pointers
@ 2021-04-19 19:57 Wesley Cheng
  2021-04-20  0:54 ` Peter Chen
  0 siblings, 1 reply; 2+ messages in thread
From: Wesley Cheng @ 2021-04-19 19:57 UTC (permalink / raw)
  To: balbi, gregkh; +Cc: linux-usb, linux-kernel, jackp, Hemant Kumar, Wesley Cheng

From: Hemant Kumar <hemantk@codeaurora.org>

Upon driver unbind usb_free_all_descriptors() function frees all
speed descriptor pointers without setting them to NULL. In case
gadget speed changes (i.e from super speed plus to super speed)
after driver unbind only upto super speed descriptor pointers get
populated. Super speed plus desc still holds the stale (already
freed) pointer. Fix this issue by setting all descriptor pointers
to NULL after freeing them in usb_free_all_descriptors().

Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
---
 drivers/usb/gadget/config.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 2d11535..8bb2577 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -194,9 +194,13 @@ EXPORT_SYMBOL_GPL(usb_assign_descriptors);
 void usb_free_all_descriptors(struct usb_function *f)
 {
 	usb_free_descriptors(f->fs_descriptors);
+	f->fs_descriptors = NULL;
 	usb_free_descriptors(f->hs_descriptors);
+	f->hs_descriptors = NULL;
 	usb_free_descriptors(f->ss_descriptors);
+	f->ss_descriptors = NULL;
 	usb_free_descriptors(f->ssp_descriptors);
+	f->ssp_descriptors = NULL;
 }
 EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

* Re: [PATCH] usb: gadget: Fix double free of device descriptor pointers
  2021-04-19 19:57 [PATCH] usb: gadget: Fix double free of device descriptor pointers Wesley Cheng
@ 2021-04-20  0:54 ` Peter Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Chen @ 2021-04-20  0:54 UTC (permalink / raw)
  To: Wesley Cheng; +Cc: balbi, gregkh, linux-usb, linux-kernel, jackp, Hemant Kumar

On 21-04-19 12:57:20, Wesley Cheng wrote:
> From: Hemant Kumar <hemantk@codeaurora.org>
> 
> Upon driver unbind usb_free_all_descriptors() function frees all
> speed descriptor pointers without setting them to NULL. In case
> gadget speed changes (i.e from super speed plus to super speed)
> after driver unbind only upto super speed descriptor pointers get
> populated. Super speed plus desc still holds the stale (already
> freed) pointer. Fix this issue by setting all descriptor pointers
> to NULL after freeing them in usb_free_all_descriptors().
> 
> Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
> Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
> ---
>  drivers/usb/gadget/config.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
> index 2d11535..8bb2577 100644
> --- a/drivers/usb/gadget/config.c
> +++ b/drivers/usb/gadget/config.c
> @@ -194,9 +194,13 @@ EXPORT_SYMBOL_GPL(usb_assign_descriptors);
>  void usb_free_all_descriptors(struct usb_function *f)
>  {
>  	usb_free_descriptors(f->fs_descriptors);
> +	f->fs_descriptors = NULL;
>  	usb_free_descriptors(f->hs_descriptors);
> +	f->hs_descriptors = NULL;
>  	usb_free_descriptors(f->ss_descriptors);
> +	f->ss_descriptors = NULL;
>  	usb_free_descriptors(f->ssp_descriptors);
> +	f->ssp_descriptors = NULL;
>  }
>  EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
>  

Reviewed-by: Peter Chen <peter.chen@kernel.org>

You may add Fixed-by tag, and cc to stable tree.

-- 

Thanks,
Peter Chen


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

end of thread, other threads:[~2021-04-20  0:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 19:57 [PATCH] usb: gadget: Fix double free of device descriptor pointers Wesley Cheng
2021-04-20  0:54 ` Peter Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.