mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: syzbot <syzbot+7bf725ed337e37307001@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] usb: gadget: inode: keep ep_data alive via the ep inode reference
Date: Fri, 04 Sep 2026 06:44:39 -0700	[thread overview]
Message-ID: <6a9acb47.c31bd8f4.21fd18.0002.GAE@google.com> (raw)
In-Reply-To: <6a8ce445.dbb3a75c.7844.0016.GAE@google.com>

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] usb: gadget: inode: keep ep_data alive via the ep inode reference
Author: adrianox@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
---
 drivers/usb/gadget/legacy/inode.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index db961aaa3740..dc0cba86cf30 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1626,6 +1626,16 @@ static int activate_ep_files (struct dev_data *dev)
 		if (!data->req)
 			goto enomem1;
 
+		/*
+		 * The inode created below references this ep_data through
+		 * ->i_private and gadgetfs_evict_inode() releases it again.
+		 * Without this the inode could outlive the ep_data and a
+		 * concurrent openat() -> ep_open() would dereference freed
+		 * memory (reported as a slab-use-after-free in the mutex fast
+		 * path).  Keep the object alive for as long as any inode points
+		 * to it.
+		 */
+		get_ep(data);
 		err = gadgetfs_create_file (dev->sb, data->name,
 				data, &ep_io_operations);
 		if (err)
@@ -2015,9 +2025,25 @@ static int gadgetfs_create_file (struct super_block *sb, char const *name,
 	return 0;
 }
 
+static void gadgetfs_evict_inode(struct inode *inode)
+{
+	/*
+	 * EP file inodes keep their struct ep_data alive through ->i_private;
+	 * drop that reference when the inode finally goes away.  This closes
+	 * the ep_open() vs. gadgetfs_unbind()/destroy_ep_files() race where
+	 * the ep_data was freed while an inode still pointed to it.
+	 */
+	if (inode->i_fop == &ep_io_operations)
+		put_ep(inode->i_private);
+
+	truncate_inode_pages_final(&inode->i_data);
+	clear_inode(inode);
+}
+
 static const struct super_operations gadget_fs_operations = {
 	.statfs =	simple_statfs,
 	.drop_inode =	inode_just_drop,
+	.evict_inode =	gadgetfs_evict_inode,
 };
 
 static int
-- 
2.51.0


      parent reply	other threads:[~2026-09-04 13:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  0:39 [syzbot] [fs?] KASAN: slab-use-after-free Write in do_bad_area syzbot
2026-08-29  9:45 ` syzbot
2026-09-04 13:44 ` syzbot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a9acb47.c31bd8f4.21fd18.0002.GAE@google.com \
    --to=syzbot+7bf725ed337e37307001@syzkaller.appspotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®