* Re: [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind [not found] <20261124091819.2275412-1-hanzhijian1991@gmail.com> @ 2026-11-24 9:18 ` syzbot 0 siblings, 0 replies; 3+ messages in thread From: syzbot @ 2026-11-24 9:18 UTC (permalink / raw) To: hanzhijian1991; +Cc: hanzhijian1991, linux-kernel, syzkaller-bugs > From: Zhijian Han <hanzhijian1991@gmail.com> > > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master Patch testing via #syz test is temporarily disabled. See https://github.com/google/syzkaller/issues/8122 for details. > > From 6d5331190d1c541e112aa26ea25f0744eecaaadf Mon Sep 17 00:00:00 2001 > From: Zhijian Han <hanzhijian1991@gmail.com> > Date: Tue, 24 Nov 2026 17:18:01 +0800 > Subject: [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind > > gadget_bind() allocates an ep0 request and stores it in dev->req, but > gadget_unbind() never releases it. The request is only freed by > dev_free(), which runs when the last reference to the raw_gadget device > is dropped. When the UDC is unbound and then bound again (e.g. via > sysfs), gadget_bind() is called a second time and overwrites dev->req > with a newly allocated request, leaking the old one. > > syzbot reproduces this by unbinding/rebinding the dummy_udc driver > through sysfs while running a raw-gadget instance: each re-bind leaks > a 128-byte dummy_hcd request. > > Free the request in gadget_unbind() instead, while the gadget and its > ep0 are still valid. Dequeue the request first if an ep0 transfer is > still in flight. > > Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5 > Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com> > --- > drivers/usb/gadget/legacy/raw_gadget.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c > index 4febf8dac..aedc7a305 100644 > --- a/drivers/usb/gadget/legacy/raw_gadget.c > +++ b/drivers/usb/gadget/legacy/raw_gadget.c > @@ -328,8 +328,30 @@ static int gadget_bind(struct usb_gadget *gadget, > static void gadget_unbind(struct usb_gadget *gadget) > { > struct raw_dev *dev = get_gadget_data(gadget); > + struct usb_request *req; > + unsigned long flags; > + bool queued; > > set_gadget_data(gadget, NULL); > + > + spin_lock_irqsave(&dev->lock, flags); > + req = dev->req; > + dev->req = NULL; > + queued = dev->ep0_urb_queued; > + spin_unlock_irqrestore(&dev->lock, flags); > + > + /* > + * Free the ep0 request allocated in gadget_bind(). If the UDC is > + * re-bound to this driver, a new gadget_bind() call would otherwise > + * overwrite dev->req and leak the previous request. Do it here, > + * while the gadget and its ep0 are still valid. > + */ > + if (req) { > + if (queued) > + usb_ep_dequeue(gadget->ep0, req); > + usb_ep_free_request(gadget->ep0, req); > + } > + > /* Matches kref_get() in gadget_bind(). */ > kref_put(&dev->count, dev_free); > } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <20261124091825.2275478-1-hanzhijian1991@gmail.com>]
* Re: [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind [not found] <20261124091825.2275478-1-hanzhijian1991@gmail.com> @ 2026-11-24 9:18 ` syzbot 0 siblings, 0 replies; 3+ messages in thread From: syzbot @ 2026-11-24 9:18 UTC (permalink / raw) To: hanzhijian1991; +Cc: hanzhijian1991, linux-kernel, syzkaller-bugs > From: Zhijian Han <hanzhijian1991@gmail.com> > > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master Patch testing via #syz test is temporarily disabled. See https://github.com/google/syzkaller/issues/8122 for details. > > From 6d5331190d1c541e112aa26ea25f0744eecaaadf Mon Sep 17 00:00:00 2001 > From: Zhijian Han <hanzhijian1991@gmail.com> > Date: Tue, 24 Nov 2026 17:18:01 +0800 > Subject: [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind > > gadget_bind() allocates an ep0 request and stores it in dev->req, but > gadget_unbind() never releases it. The request is only freed by > dev_free(), which runs when the last reference to the raw_gadget device > is dropped. When the UDC is unbound and then bound again (e.g. via > sysfs), gadget_bind() is called a second time and overwrites dev->req > with a newly allocated request, leaking the old one. > > syzbot reproduces this by unbinding/rebinding the dummy_udc driver > through sysfs while running a raw-gadget instance: each re-bind leaks > a 128-byte dummy_hcd request. > > Free the request in gadget_unbind() instead, while the gadget and its > ep0 are still valid. Dequeue the request first if an ep0 transfer is > still in flight. > > Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5 > Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com> > --- > drivers/usb/gadget/legacy/raw_gadget.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c > index 4febf8dac..aedc7a305 100644 > --- a/drivers/usb/gadget/legacy/raw_gadget.c > +++ b/drivers/usb/gadget/legacy/raw_gadget.c > @@ -328,8 +328,30 @@ static int gadget_bind(struct usb_gadget *gadget, > static void gadget_unbind(struct usb_gadget *gadget) > { > struct raw_dev *dev = get_gadget_data(gadget); > + struct usb_request *req; > + unsigned long flags; > + bool queued; > > set_gadget_data(gadget, NULL); > + > + spin_lock_irqsave(&dev->lock, flags); > + req = dev->req; > + dev->req = NULL; > + queued = dev->ep0_urb_queued; > + spin_unlock_irqrestore(&dev->lock, flags); > + > + /* > + * Free the ep0 request allocated in gadget_bind(). If the UDC is > + * re-bound to this driver, a new gadget_bind() call would otherwise > + * overwrite dev->req and leak the previous request. Do it here, > + * while the gadget and its ep0 are still valid. > + */ > + if (req) { > + if (queued) > + usb_ep_dequeue(gadget->ep0, req); > + usb_ep_free_request(gadget->ep0, req); > + } > + > /* Matches kref_get() in gadget_bind(). */ > kref_put(&dev->count, dev_free); > } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <20261124091833.2275524-1-hanzhijian1991@gmail.com>]
* Re: [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind [not found] <20261124091833.2275524-1-hanzhijian1991@gmail.com> @ 2026-11-24 9:18 ` syzbot 0 siblings, 0 replies; 3+ messages in thread From: syzbot @ 2026-11-24 9:18 UTC (permalink / raw) To: hanzhijian1991; +Cc: hanzhijian1991, linux-kernel, syzkaller-bugs > From: Zhijian Han <hanzhijian1991@gmail.com> > > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master Patch testing via #syz test is temporarily disabled. See https://github.com/google/syzkaller/issues/8122 for details. > > From 6d5331190d1c541e112aa26ea25f0744eecaaadf Mon Sep 17 00:00:00 2001 > From: Zhijian Han <hanzhijian1991@gmail.com> > Date: Tue, 24 Nov 2026 17:18:01 +0800 > Subject: [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind > > gadget_bind() allocates an ep0 request and stores it in dev->req, but > gadget_unbind() never releases it. The request is only freed by > dev_free(), which runs when the last reference to the raw_gadget device > is dropped. When the UDC is unbound and then bound again (e.g. via > sysfs), gadget_bind() is called a second time and overwrites dev->req > with a newly allocated request, leaking the old one. > > syzbot reproduces this by unbinding/rebinding the dummy_udc driver > through sysfs while running a raw-gadget instance: each re-bind leaks > a 128-byte dummy_hcd request. > > Free the request in gadget_unbind() instead, while the gadget and its > ep0 are still valid. Dequeue the request first if an ep0 transfer is > still in flight. > > Reported-by: syzbot+d83b3c49738aea97c0e5@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=d83b3c49738aea97c0e5 > Signed-off-by: Zhijian Han <hanzhijian1991@gmail.com> > --- > drivers/usb/gadget/legacy/raw_gadget.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c > index 4febf8dac..aedc7a305 100644 > --- a/drivers/usb/gadget/legacy/raw_gadget.c > +++ b/drivers/usb/gadget/legacy/raw_gadget.c > @@ -328,8 +328,30 @@ static int gadget_bind(struct usb_gadget *gadget, > static void gadget_unbind(struct usb_gadget *gadget) > { > struct raw_dev *dev = get_gadget_data(gadget); > + struct usb_request *req; > + unsigned long flags; > + bool queued; > > set_gadget_data(gadget, NULL); > + > + spin_lock_irqsave(&dev->lock, flags); > + req = dev->req; > + dev->req = NULL; > + queued = dev->ep0_urb_queued; > + spin_unlock_irqrestore(&dev->lock, flags); > + > + /* > + * Free the ep0 request allocated in gadget_bind(). If the UDC is > + * re-bound to this driver, a new gadget_bind() call would otherwise > + * overwrite dev->req and leak the previous request. Do it here, > + * while the gadget and its ep0 are still valid. > + */ > + if (req) { > + if (queued) > + usb_ep_dequeue(gadget->ep0, req); > + usb_ep_free_request(gadget->ep0, req); > + } > + > /* Matches kref_get() in gadget_bind(). */ > kref_put(&dev->count, dev_free); > } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 9:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261124091819.2275412-1-hanzhijian1991@gmail.com>
2026-11-24 9:18 ` [PATCH] usb: gadget: raw_gadget: fix ep0 request leak on unbind syzbot
[not found] <20261124091825.2275478-1-hanzhijian1991@gmail.com>
2026-11-24 9:18 ` syzbot
[not found] <20261124091833.2275524-1-hanzhijian1991@gmail.com>
2026-11-24 9:18 ` syzbot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox