mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Wesley Cheng <quic_wcheng@quicinc.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH 1/2] Revert "usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration"
Date: Sat, 1 Mar 2025 02:01:33 +0000	[thread overview]
Message-ID: <20250301020131.z7osit3xcqhwrl3n@synopsys.com> (raw)
In-Reply-To: <20250301003452.2675360-2-quic_wcheng@quicinc.com>

Hi,

On Fri, Feb 28, 2025, Wesley Cheng wrote:
> This reverts commit 1ff24d40b3c3c673d833c546f898133b80dffc39.
> 
> The following change creates a potential use after freed scenario within
> the UDC core level.  When transitioning from peripheral to host mode, the
> DWC3 DRD will remove the USB UDC using usb_del_gadget().  As part of the
> UDC removal routine, the UDC core will issue a pullup disable call back to
> the DWC3 gadget driver, which will now call usb_gadget_set_state(), and
> queues gadget->work.  If gadget->work is unable to complete before the USB
> gadget is freed, then we will run into the use after freed situation.
> 
> Below is the callstack in question:
> 
> dwc3_gadget_exit()
>  --> usb_del_gadget()
>  --> gadget_unbind_driver()
>   --> device_del()
>    --> gadget_unbind_driver()
>     --> usb_gadget_disconnect_locked()
>      --> pullup(0)
>       --> dwc3_gadget_soft_disconnect()
>        --> usb_gadget_set_state(UNATTACHED)
>         --> queue_work(gadget->work) --> async
>   --> device_unregister()
> 
> Unfortunately, the flush_work() call within usb_del_gadget() doesn't work
> in this situation, as it happens before the device_del() and soft
> disconnect sequence.
> 
> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
> ---
>  drivers/usb/dwc3/gadget.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 5156fafbda6c..921f72995dbf 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2781,8 +2781,6 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)
>  	__dwc3_gadget_stop(dwc);
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  
> -	usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED);
> -
>  	return ret;
>  }
>  

Have you tried with this fix?
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=399a45e5237ca14037120b1b895bd38a3b4492ea

BR,
Thinh

  reply	other threads:[~2025-03-01  2:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-01  0:34 [PATCH 0/2] Fix use after freed situation in UDC core Wesley Cheng
2025-03-01  0:34 ` [PATCH 1/2] Revert "usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration" Wesley Cheng
2025-03-01  2:01   ` Thinh Nguyen [this message]
2025-03-01  2:33     ` Wesley Cheng
2025-03-03 23:24       ` Thinh Nguyen
2025-03-01  0:34 ` [PATCH 2/2] usb: gadget: udc: Update USB gadget state during soft disconnect Wesley Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250301020131.z7osit3xcqhwrl3n@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_wcheng@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®