mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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; 5+ 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	[flat|nested] 5+ messages in thread
[parent not found: <1729447050-0-patch-2-2-raw-gadget@kvack.org>]

end of thread, other threads:[~2026-11-23  1:18 UTC | newest]

Thread overview: 5+ 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
     [not found] <1729447050-0-patch-2-2-raw-gadget@kvack.org>
2026-11-23  1:17 ` Zhijian Han

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

all inboxes | Powered by JetHome®