Linux USB
 help / color / mirror / Atom feed
* [PATCH usb-next v1] USB: gadget: Fix UAF in gadgetfs_fill_super()
@ 2026-09-02  5:01 Rafael Alejandro Diaz Cruz
  2026-09-02 14:38 ` Alan Stern
  0 siblings, 1 reply; 6+ messages in thread
From: Rafael Alejandro Diaz Cruz @ 2026-09-02  5:01 UTC (permalink / raw)
  To: gregkh
  Cc: linux-usb, linux-kernel, Rafael Alejandro Diaz Cruz,
	syzbot+4a5c87a01894ca37f25c

UAF is caused by syzkaller reproducer forcing
the failure of gadgetfs_fill_super()

When gadgetfs_fill_super() fails, it's error path calls
put_dev() which drops refcount inside the_device to 0
and frees the objet. But the_device pointer is not
cleared, leading to point at freed memory.

VFS will then call gadgetfs_kill_sb() after mount
failure leading to put_dev() to be called on the
already freed pointer.

Fix by setting the_device = NULL during error path
before calling put_dev() inside gadgetfs_fill_super()
so that gadgetfs_kill_sb() skips put_dev().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+4a5c87a01894ca37f25c@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=4a5c87a01894ca37f25c
Signed-off-by: Rafael Alejandro Diaz Cruz <rafad900@gmail.com>
---
 drivers/usb/gadget/legacy/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index d87a8ab51510..3e2bce7543d4 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -2059,6 +2059,7 @@ gadgetfs_fill_super (struct super_block *sb, struct fs_context *fc)
 	rc = gadgetfs_create_file(sb, CHIP, dev, &ep0_operations);
 	if (rc) {
 		put_dev(dev);
+		the_device = NULL;
 		goto Enomem;
 	}
 
-- 
2.43.0


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

end of thread, other threads:[~2026-09-04 16:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  5:01 [PATCH usb-next v1] USB: gadget: Fix UAF in gadgetfs_fill_super() Rafael Alejandro Diaz Cruz
2026-09-02 14:38 ` Alan Stern
     [not found]   ` <CALp66yF0MZy9UKo_qGGeekxV0RNMNKZ_foqADVnqg+_YgEYqEA@mail.gmail.com>
2026-09-03 14:28     ` Alan Stern
2026-09-04  5:12       ` Rafael Alejandro Díaz Cruz
2026-09-04  5:17         ` Greg KH
2026-09-04 16:33         ` Alan Stern

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