From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Cole Munz <Munzzyy1@proton.me>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Udipto Goswami <quic_ugoswami@quicinc.com>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: f_fs: only dequeue ep0req when it is queued
Date: Fri, 20 Nov 2026 11:19:49 +0100 [thread overview]
Message-ID: <2026112034-buccaneer-corrode-5da3@gregkh> (raw)
In-Reply-To: <fe62c0a656fe8870248e6a17641f6841bc66d65e.1788885869.git.Munzzyy1@proton.me>
On Tue, Sep 08, 2026 at 04:56:38PM +0000, Cole Munz wrote:
> Commit ce405d561b02 ("usb: gadget: f_fs: Ensure ep0req is dequeued
> before free_request") made functionfs_unbind() call usb_ep_dequeue()
> on ep0req unconditionally before freeing it. That closed a real
> use-after-free: a reader or writer parked in __ffs_ep0_queue_wait()
> holds ffs->mutex and waits on ep0req_completion while the request is
> in flight, and unbind has to force it to complete so that thread wakes
> up, returns, and drops the mutex before the request is freed.
>
> Problem is, unbind now dequeues every single time it runs, and the
> parked-reader case is rare. Far more often ep0req already completed
> on its own, or it was never queued in the first place because bind
> failed before any control transfer reached us. dwc3 is not quiet
> about the second case. dwc3_gadget_ep_dequeue() logs "request %p was
> not queued to %s" whenever the request isn't sitting on one of the
> endpoint's lists, so ordinary gadget teardown, and any boot where the
> host never finished enumeration before the driver unbound, prints
> that error right before the "failed to start ...: -19" that follows.
>
> The fix is to track whether ep0req is actually queued on ep0, and
> only call usb_ep_dequeue() in functionfs_unbind() when it is.
> ep0req_queued gets set right before usb_ep_queue() in
> __ffs_ep0_queue_wait(), cleared again if that call fails, and cleared
> in ffs_ep0_complete() once the request comes back. The parked-reader
> case still works the same way it always did: the flag stays true for
> as long as the thread sits blocked in
> wait_for_completion_interruptible(), so unbind still finds it queued
> and still dequeues. In the other two cases the flag reads false and
> unbind skips a call that was doing nothing anyway.
>
> Fixes: ce405d561b02 ("usb: gadget: f_fs: Ensure ep0req is dequeued before free_request")
> Assisted-by: LLM sparse
> Signed-off-by: Cole Munz <Munzzyy1@proton.me>
> ---
> This is the f_fs-side fix Thinh suggested on the dwc3 thread rather than
> changing dwc3_gadget_ep_dequeue()'s return, and it also quiets the boot
> case that the dwc3 change did not:
> https://lore.kernel.org/linux-usb/aptrIbp-p6RNGd9X@vbox/
>
> Built for arm64, f_fs.o compiles with no new warnings, sparse clean,
> checkpatch --strict reports nothing. I can't flash a gadget here, so the
> runtime side is reasoned from source, not tested on hardware.
Please test it on real hardware before submitting it again.
thanks,
greg k-h
prev parent reply other threads:[~2026-11-20 10:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 16:56 [PATCH] usb: gadget: f_fs: only dequeue ep0req when it is queued Cole Munz
2026-11-20 10:19 ` Greg Kroah-Hartman [this message]
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=2026112034-buccaneer-corrode-5da3@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=Munzzyy1@proton.me \
--cc=Thinh.Nguyen@synopsys.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_ugoswami@quicinc.com \
--cc=viro@zeniv.linux.org.uk \
/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