From: Wesley Cheng <quic_wcheng@quicinc.com>
To: <gregkh@linuxfoundation.org>, <Thinh.Nguyen@synopsys.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
Wesley Cheng <quic_wcheng@quicinc.com>
Subject: [PATCH 1/2] Revert "usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration"
Date: Fri, 28 Feb 2025 16:34:51 -0800 [thread overview]
Message-ID: <20250301003452.2675360-2-quic_wcheng@quicinc.com> (raw)
In-Reply-To: <20250301003452.2675360-1-quic_wcheng@quicinc.com>
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;
}
next prev parent reply other threads:[~2025-03-01 0:35 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 ` Wesley Cheng [this message]
2025-03-01 2:01 ` [PATCH 1/2] Revert "usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration" Thinh Nguyen
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=20250301003452.2675360-2-quic_wcheng@quicinc.com \
--to=quic_wcheng@quicinc.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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®