* [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure
@ 2026-08-22 2:48 hanzhijian
2026-09-30 18:32 ` Andrey Konovalov
2026-11-20 13:17 ` Greg Kroah-Hartman
0 siblings, 2 replies; 7+ messages in thread
From: hanzhijian @ 2026-08-22 2:48 UTC (permalink / raw)
To: Andrey Konovalov, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, hanzhijian, syzbot+d83b3c49738aea97c0e5
gadget_bind() allocates an ep0 request and stores it in dev->req. If
raw_queue_event() fails to queue the connect event, the function
returns without releasing the request, leaking it.
Release the request before returning in that case.
Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
Signed-off-by: hanzhijian <hanzhijian1991@gmail.com>
---
drivers/usb/gadget/legacy/raw_gadget.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
index 4febf8dac..33d70b552 100644
--- a/drivers/usb/gadget/legacy/raw_gadget.c
+++ b/drivers/usb/gadget/legacy/raw_gadget.c
@@ -316,6 +316,8 @@ static int gadget_bind(struct usb_gadget *gadget,
ret = raw_queue_event(dev, USB_RAW_EVENT_CONNECT, 0, NULL);
if (ret < 0) {
dev_err(&gadget->dev, "failed to queue connect event\n");
+ usb_ep_free_request(gadget->ep0, dev->req);
+ dev->req = NULL;
set_gadget_data(gadget, NULL);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure
2026-08-22 2:48 [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure hanzhijian
@ 2026-09-30 18:32 ` Andrey Konovalov
2026-11-20 13:17 ` Greg Kroah-Hartman
1 sibling, 0 replies; 7+ messages in thread
From: Andrey Konovalov @ 2026-09-30 18:32 UTC (permalink / raw)
To: hanzhijian
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel,
syzbot+d83b3c49738aea97c0e5
On Sat, Aug 22, 2026 at 6:34 AM hanzhijian <hanzhijian1991@gmail.com> wrote:
>
> gadget_bind() allocates an ep0 request and stores it in dev->req. If
> raw_queue_event() fails to queue the connect event, the function
> returns without releasing the request, leaking it.
>
> Release the request before returning in that case.
>
> Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
> Signed-off-by: hanzhijian <hanzhijian1991@gmail.com>
> ---
> drivers/usb/gadget/legacy/raw_gadget.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
> index 4febf8dac..33d70b552 100644
> --- a/drivers/usb/gadget/legacy/raw_gadget.c
> +++ b/drivers/usb/gadget/legacy/raw_gadget.c
> @@ -316,6 +316,8 @@ static int gadget_bind(struct usb_gadget *gadget,
> ret = raw_queue_event(dev, USB_RAW_EVENT_CONNECT, 0, NULL);
> if (ret < 0) {
> dev_err(&gadget->dev, "failed to queue connect event\n");
> + usb_ep_free_request(gadget->ep0, dev->req);
> + dev->req = NULL;
> set_gadget_data(gadget, NULL);
> return ret;
> }
> --
> 2.43.0
>
Maybe this is a valid fix (though it's not obvious: dev->req should
get freed in dev_free() even in case of an error here), but it is
unrelated to the referenced syzbot issue (cause by bind-unbind-bind
sequence). LLM?
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure
2026-08-22 2:48 [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure hanzhijian
2026-09-30 18:32 ` Andrey Konovalov
@ 2026-11-20 13:17 ` Greg Kroah-Hartman
2026-11-23 1:18 ` Zhijian Han
2026-11-23 5:50 ` [PATCH v2] " Zhijian Han
1 sibling, 2 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-20 13:17 UTC (permalink / raw)
To: hanzhijian
Cc: Andrey Konovalov, linux-usb, linux-kernel,
syzbot+d83b3c49738aea97c0e5
On Sat, Aug 22, 2026 at 10:48:50AM +0800, hanzhijian wrote:
> gadget_bind() allocates an ep0 request and stores it in dev->req. If
> raw_queue_event() fails to queue the connect event, the function
> returns without releasing the request, leaking it.
>
> Release the request before returning in that case.
>
> Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
> Signed-off-by: hanzhijian <hanzhijian1991@gmail.com>
Full name please.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure
2026-11-20 13:17 ` Greg Kroah-Hartman
@ 2026-11-23 1:18 ` Zhijian Han
2026-11-23 5:50 ` [PATCH v2] " Zhijian Han
1 sibling, 0 replies; 7+ messages in thread
From: Zhijian Han @ 2026-11-23 1:18 UTC (permalink / raw)
To: gregkh
Cc: andreyknvl, linux-usb, linux-kernel, syzbot+d83b3c49738aea97c0e5,
Zhijian Han
On Fri, Nov 20, 2026 at 09:17:32PM +0800, Greg Kroah-Hartman wrote:
> On Sat, Aug 22, 2026 at 10:48:50AM +0800, hanzhijian wrote:
> > gadget_bind() allocates an ep0 request and stores it in dev->req. If
> > raw_queue_event() fails to queue the connect event, the function
> > returns without releasing the request, leaking it.
> >
> > Release the request before returning in that case.
> >
> > Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
> > Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
> > Signed-off-by: hanzhijian <hanzhijian1991@gmail.com>
>
> Full name please.
Apologies. Please use:
Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com>
Best regards,
Zhijian Han
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] usb: gadget: raw_gadget: fix memory leak on connect event failure
2026-11-20 13:17 ` Greg Kroah-Hartman
2026-11-23 1:18 ` Zhijian Han
@ 2026-11-23 5:50 ` Zhijian Han
2026-11-23 6:00 ` Greg KH
2026-11-23 6:05 ` sashiko-bot
1 sibling, 2 replies; 7+ messages in thread
From: Zhijian Han @ 2026-11-23 5:50 UTC (permalink / raw)
To: gregkh
Cc: andreyknvl, linux-usb, linux-kernel, syzbot+d83b3c49738aea97c0e5,
Zhijian Han
gadget_bind() allocates an ep0 request and stores it in dev->req. If
raw_queue_event() fails to queue the connect event, the function
returns without releasing the request, leaking it.
Release the request before returning in that case.
Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com>
Changes in v2:
- Fix author name and add missing Signed-off-by (full name), as
requested by Greg KH.
- Fix author name and add missing Signed-off-by (full name), as
requested by Greg KH.
---
drivers/usb/gadget/legacy/raw_gadget.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
index 4febf8dac7ca..33d70b552b6d 100644
--- a/drivers/usb/gadget/legacy/raw_gadget.c
+++ b/drivers/usb/gadget/legacy/raw_gadget.c
@@ -316,6 +316,8 @@ static int gadget_bind(struct usb_gadget *gadget,
ret = raw_queue_event(dev, USB_RAW_EVENT_CONNECT, 0, NULL);
if (ret < 0) {
dev_err(&gadget->dev, "failed to queue connect event\n");
+ usb_ep_free_request(gadget->ep0, dev->req);
+ dev->req = NULL;
set_gadget_data(gadget, NULL);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2] usb: gadget: raw_gadget: fix memory leak on connect event failure
2026-11-23 5:50 ` [PATCH v2] " Zhijian Han
@ 2026-11-23 6:00 ` Greg KH
2026-11-23 6:05 ` sashiko-bot
1 sibling, 0 replies; 7+ messages in thread
From: Greg KH @ 2026-11-23 6:00 UTC (permalink / raw)
To: Zhijian Han
Cc: andreyknvl, linux-usb, linux-kernel, syzbot+d83b3c49738aea97c0e5
On Mon, Nov 23, 2026 at 01:50:27PM +0800, Zhijian Han wrote:
> gadget_bind() allocates an ep0 request and stores it in dev->req. If
> raw_queue_event() fails to queue the connect event, the function
> returns without releasing the request, leaking it.
>
> Release the request before returning in that case.
>
> Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
> Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com>
>
> Changes in v2:
> - Fix author name and add missing Signed-off-by (full name), as
> requested by Greg KH.
>
> - Fix author name and add missing Signed-off-by (full name), as
> requested by Greg KH.
This goes below the --- line. And why list it twice?
confused,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] usb: gadget: raw_gadget: fix memory leak on connect event failure
2026-11-23 5:50 ` [PATCH v2] " Zhijian Han
2026-11-23 6:00 ` Greg KH
@ 2026-11-23 6:05 ` sashiko-bot
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-23 6:05 UTC (permalink / raw)
To: Zhijian Han; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: raw_gadget: missing Fixes trailer for gadget_bind()
leak fix
--
commit 94d8269bfbf48dae28738ed0656c12041e15b31d
Author: Zhijian Han <hanzhijian1991@gmail.com>
> usb: gadget: raw_gadget: fix memory leak on connect event failure
>
> gadget_bind() allocates an ep0 request and stores it in dev->req. If
> raw_queue_event() fails to queue the connect event, the function
> returns without releasing the request, leaking it.
>
> Release the request before returning in that case.
>
> Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5
> Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com>
>
> Changes in v2:
> - Fix author name and add missing Signed-off-by (full name), as
> requested by Greg KH.
>
> - Fix author name and add missing Signed-off-by (full name), as
> requested by Greg KH.
[Severity: Low]
Since this fixes a memory leak in gadget_bind(), should it include a
Fixes: tag:
Fixes: f2c2e717642c ("usb: gadget: add raw-gadget interface")
Also, the "Changes in v2" entry is duplicated in the commit message body.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123055027.1141887-1-hanzhijian1991@gmail.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-23 6:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-22 2:48 [PATCH 2/2] usb: gadget: raw_gadget: fix memory leak on connect event failure hanzhijian
2026-09-30 18:32 ` Andrey Konovalov
2026-11-20 13:17 ` Greg Kroah-Hartman
2026-11-23 1:18 ` Zhijian Han
2026-11-23 5:50 ` [PATCH v2] " Zhijian Han
2026-11-23 6:00 ` Greg KH
2026-11-23 6:05 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox