From: sashiko-bot@kernel.org
To: "Jaegyun Lee" <dreams200260@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: f_midi: restart IN transfers after SET_INTERFACE
Date: Sun, 29 Nov 2026 14:17:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-239692@kernel.org> (raw)
In-Reply-To: <20261129140555.651497-1-dreams200260@gmail.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] usb: gadget: f_midi: use-after-free race in
f_midi_complete() [1]
--
commit e9b2887e99b3e3e822534d3a7636ce9d94ac700a
Author: Jaegyun Lee <dreams200260@gmail.com>
usb: gadget: f_midi: restart IN transfers after SET_INTERFACE
This commit resets req->length on aborted IN requests in f_midi_complete()
and schedules midi->work at the end of f_midi_set_alt() so IN transfers
resume after SET_INTERFACE.
> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
> index 28d2e9db2450d..3e71ccb173a3a 100644
> --- a/drivers/usb/gadget/function/f_midi.c
> +++ b/drivers/usb/gadget/function/f_midi.c
> @@ -299,6 +299,8 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req)
> /* We don't need to free IN requests because it's handled
> * by the midi->in_req_fifo. */
> free_ep_req(ep, req);
> + } else if (ep == midi->in_ep) {
> + req->length = 0;
> }
> return;
[Severity: Critical]
This problem wasn't introduced by this patch, but can f_midi_complete() hit
a use-after-free on req [1] when f_midi_disable() runs concurrently?
When an IN request is queued, its pointer stays in midi->in_req_fifo. On
normal completion, the UDC driver drops its controller lock before calling
usb_gadget_giveback_request(), and usb_ep_disable() does not wait for
in-flight completion callbacks to finish:
CPU0 CPU1
usb_gadget_giveback_request()
f_midi_complete()
f_midi_disable()
usb_ep_disable(midi->in_ep)
while (kfifo_get(&midi->in_req_fifo,
&req))
free_ep_req(midi->in_ep, req)
req->length = 0; <-- use-after-free
queue_work(..., &midi->work);
If a disconnect or configuration change calls f_midi_disable() while an IN
completion is entering f_midi_complete(), f_midi_disable() drains
midi->in_req_fifo and frees req before f_midi_complete() writes to
req->length and queues midi->work.
[1] https://sashiko.dev/#/bug/linux-22a882f3-c221-4b3e-aa74-b2c3c35d00ab
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129140555.651497-1-dreams200260@gmail.com?part=1
prev parent reply other threads:[~2026-11-29 14:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 14:05 [PATCH] usb: gadget: f_midi: restart IN transfers after SET_INTERFACE Jaegyun Lee
2026-11-29 14:17 ` sashiko-bot [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=sashiko-outbox-239692@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dreams200260@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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