linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: fix device data management error in gadgetfs_bind()
@ 2026-08-03  9:12 Dmitry Antipov
  2026-08-03  9:15 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Antipov @ 2026-08-03  9:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Al Viro, linux-usb, lvc-project, Dmitry Antipov,
	syzbot+6aa97991da41499aa852, stable

In 'gadgetfs_bind()', 'get_dev()' on appropriate 'struct dev_data'
instance should be performed immediately after the pointer is stored.
Otherwise an attempt to handle -ENOMEM later will issue an unbalanced
'put_dev()' in 'gadgetfs_unbind()', thus leading to UAF errors.

Reported-by: syzbot+6aa97991da41499aa852@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6aa97991da41499aa852
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/usb/gadget/legacy/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index d87a8ab51510..a86a1c68903e 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1681,6 +1681,7 @@ static int gadgetfs_bind(struct usb_gadget *gadget,
 	set_gadget_data (gadget, dev);
 	dev->gadget = gadget;
 	gadget->ep0->driver_data = dev;
+	get_dev(dev);
 
 	/* preallocate control response and buffer */
 	dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
@@ -1696,7 +1697,6 @@ static int gadgetfs_bind(struct usb_gadget *gadget,
 	spin_lock_irq(&dev->lock);
 	dev->state = STATE_DEV_UNCONNECTED;
 	spin_unlock_irq(&dev->lock);
-	get_dev (dev);
 	return 0;
 
 enomem:
-- 
2.55.0


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

end of thread, other threads:[~2026-08-03 14:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03  9:12 [PATCH] usb: gadget: fix device data management error in gadgetfs_bind() Dmitry Antipov
2026-08-03  9:15 ` Greg Kroah-Hartman
2026-08-03 10:33   ` Dmitry Antipov
2026-08-03 12:24     ` Greg Kroah-Hartman
2026-08-03 13:08       ` Dmitry Antipov
2026-08-03 12:25     ` Greg Kroah-Hartman
2026-08-03 13:13       ` Dmitry Antipov
2026-08-03 13:26         ` Greg Kroah-Hartman
2026-08-03 13:36           ` Greg Kroah-Hartman
2026-08-03 14:05             ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).