* [PATCH] usb: gadget: f_midi2: disable endpoints before freeing descriptors
@ 2026-11-20 4:26 Haoli Zhang
2026-11-20 4:38 ` sashiko-bot
` (3 more replies)
0 siblings, 4 replies; 6+ 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] 6+ 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
2026-11-20 8:10 ` Greg KH
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ 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] 6+ 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
@ 2026-11-20 8:10 ` Greg KH
2026-11-20 8:10 ` Greg KH
2026-11-20 9:21 ` [PATCH v2] " Haoli Zhang
3 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2026-11-20 8:10 UTC (permalink / raw)
To: Haoli Zhang; +Cc: linux-usb
On Fri, Nov 20, 2026 at 12:26:07PM +0800, Haoli Zhang wrote:
> 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. */
That's not a good description of this function at all :(
> +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);
Please just open-code the function you tried to write above, it will
make more sense here.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ 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
2026-11-20 8:10 ` Greg KH
@ 2026-11-20 8:10 ` Greg KH
2026-11-20 9:21 ` [PATCH v2] " Haoli Zhang
3 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2026-11-20 8:10 UTC (permalink / raw)
To: Haoli Zhang; +Cc: linux-usb
On Fri, Nov 20, 2026 at 12:26:07PM +0800, Haoli Zhang wrote:
> 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>
Why are none of these people on the cc:?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] 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
` (2 preceding siblings ...)
2026-11-20 8:10 ` Greg KH
@ 2026-11-20 9:21 ` Haoli Zhang
2026-11-20 9:29 ` sashiko-bot
3 siblings, 1 reply; 6+ messages in thread
From: Haoli Zhang @ 2026-11-20 9:21 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Jinning Zhang, Bin Yu, syzbot+599d4e8994a656eafe15
The dummy_hcd driver keeps pointers to endpoint descriptors while endpoints
are enabled. Its timer dereferences these pointers in find_endpoint().
However, f_midi2_unbind() frees the function descriptors, while
f_midi2_disable() currently only resets operation_mode. Disable the
endpoints before the unbind callback releases their descriptors.
Disable the MIDI 1.0 endpoints and all MIDI 2.0 endpoints from
f_midi2_disable(). Check each endpoint pointer because the configured
direction can leave an endpoint unallocated. Keep f_midi2_stop_eps()
unchanged so altsetting transitions retain their existing request cleanup
behavior.
Fixes: 8b645922b223 ("usb: gadget: Add support for USB MIDI 2.0 function driver")
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>
---
v2:
- Open-code the endpoint disable calls in f_midi2_disable() as requested by
Greg.
- Add both co-developers to the Cc list.
drivers/usb/gadget/function/f_midi2.c | 15 +++++++++++++++
1 file changed, 15 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
@@ -1343,8 +1343,23 @@
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;
+
+ if (midi2->midi1_ep_in.usb_ep)
+ usb_ep_disable(midi2->midi1_ep_in.usb_ep);
+ if (midi2->midi1_ep_out.usb_ep)
+ usb_ep_disable(midi2->midi1_ep_out.usb_ep);
+
+ for (i = 0; i < midi2->num_eps; i++) {
+ ep = &midi2->midi2_eps[i];
+ if (ep->ep_in.usb_ep)
+ usb_ep_disable(ep->ep_in.usb_ep);
+ if (ep->ep_out.usb_ep)
+ usb_ep_disable(ep->ep_out.usb_ep);
+ }
}
/*
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] usb: gadget: f_midi2: disable endpoints before freeing descriptors
2026-11-20 9:21 ` [PATCH v2] " Haoli Zhang
@ 2026-11-20 9:29 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-20 9:29 UTC (permalink / raw)
To: Haoli Zhang; +Cc: linux-usb
> The dummy_hcd driver keeps pointers to endpoint descriptors while endpoints
> are enabled. Its timer dereferences these pointers in find_endpoint().
> However, f_midi2_unbind() frees the function descriptors, while
> f_midi2_disable() currently only resets operation_mode. Disable the
> endpoints before the unbind callback releases their descriptors.
>
> Disable the MIDI 1.0 endpoints and all MIDI 2.0 endpoints from
> f_midi2_disable(). Check each endpoint pointer because the configured
> direction can leave an endpoint unallocated. Keep f_midi2_stop_eps()
> unchanged so altsetting transitions retain their existing request cleanup
> behavior.
>
> Fixes: 8b645922b223 ("usb: gadget: Add support for USB MIDI 2.0 function driver")
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120092129.1388279-1-26031212468@stu.xidian.edu.cn?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-20 9:29 UTC | newest]
Thread overview: 6+ 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
2026-11-20 8:10 ` Greg KH
2026-11-20 8:10 ` Greg KH
2026-11-20 9:21 ` [PATCH v2] " Haoli Zhang
2026-11-20 9:29 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.