Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors
@ 2026-11-20  4:26 Haoli Zhang
  2026-11-20  4:38 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Haoli Zhang @ 2026-11-20  4:26 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Haoli Zhang

The dummy_hcd driver keeps a pointer to an endpoint descriptor while the
endpoint is enabled, and its timer dereferences that pointer in
find_endpoint(). However, f_midi2_unbind() frees the function descriptors,
while f_midi2_disable() currently only resets operation_mode. When the
function is removed, an endpoint can therefore remain enabled while its
descriptor storage is released.

Disable the MIDI 1.0 endpoints and all MIDI 2.0 endpoints from
f_midi2_disable() before the unbind callback releases the descriptors.
Keep f_midi2_stop_eps() unchanged so altsetting transitions retain their
existing request cleanup behavior.

Reported-by: syzbot+599d4e8994a656eafe15@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=599d4e8994a656eafe15
Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn>
---
 drivers/usb/gadget/function/f_midi2.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c
--- a/drivers/usb/gadget/function/f_midi2.c
+++ b/drivers/usb/gadget/function/f_midi2.c
@@ -1167,6 +1167,13 @@
 	f_midi2_free_ep_reqs(ep_out);
 }

+/* Disable an EP before its descriptors are released. */
+static void f_midi2_disable_ep(struct f_midi2_usb_ep *usb_ep)
+{
+	if (usb_ep->usb_ep)
+		usb_ep_disable(usb_ep->usb_ep);
+}
+
 /* start/queue both IN and OUT EPs */
 static int f_midi2_start_eps(struct f_midi2_usb_ep *ep_in,
 			     struct f_midi2_usb_ep *ep_out,
@@ -1343,8 +1350,17 @@
 static void f_midi2_disable(struct usb_function *fn)
 {
 	struct f_midi2 *midi2 = func_to_midi2(fn);
+	struct f_midi2_ep *ep;
+	int i;

 	midi2->operation_mode = MIDI_OP_MODE_UNSET;
+	f_midi2_disable_ep(&midi2->midi1_ep_in);
+	f_midi2_disable_ep(&midi2->midi1_ep_out);
+	for (i = 0; i < midi2->num_eps; i++) {
+		ep = &midi2->midi2_eps[i];
+		f_midi2_disable_ep(&ep->ep_in);
+		f_midi2_disable_ep(&ep->ep_out);
+	}
 }

 /*
-- 
2.43.0


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

* Re: [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors
  2026-11-20  4:26 [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors Haoli Zhang
@ 2026-11-20  4:38 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-20  4:38 UTC (permalink / raw)
  To: Haoli Zhang; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: f_midi2: missing Fixes trailer in commit message
--

commit d500c7a9c97bc7945c1213bb986d1745dbdddb98
Author: Haoli Zhang <26031212468@stu.xidian.edu.cn>

> usb: gadget: f_midi2: disable endpoints before freeing descriptors
>
> The dummy_hcd driver keeps a pointer to an endpoint descriptor while the
> endpoint is enabled, and its timer dereferences that pointer in
> find_endpoint(). However, f_midi2_unbind() frees the function descriptors,
> while f_midi2_disable() currently only resets operation_mode. When the
> function is removed, an endpoint can therefore remain enabled while its
> descriptor storage is released.
>
> Disable the MIDI 1.0 endpoints and all MIDI 2.0 endpoints from
> f_midi2_disable() before the unbind callback releases the descriptors.
> Keep f_midi2_stop_eps() unchanged so altsetting transitions retain their
> existing request cleanup behavior.
>
> Reported-by: syzbot+599d4e8994a656eafe15@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=599d4e8994a656eafe15
> Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
> Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
> Co-developed-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn>

[Severity: Low]
Since this fixes a descriptor use-after-free in f_midi2_disable(), should
the commit message include:

  Fixes: 8b645922b223 ("usb: gadget: Add support for USB MIDI 2.0 function driver")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120042607.1347854-1-26031212468@stu.xidian.edu.cn?part=1

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

end of thread, other threads:[~2026-11-20  4:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  4:26 [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors Haoli Zhang
2026-11-20  4:38 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox