From: syzbot <syzbot+54648a6c1187a7ef46a6@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] media: em28xx: clear dev->v4l2 on v4l2 init failure
Date: Mon, 02 Nov 2026 02:37:54 -0800 [thread overview]
Message-ID: <6ae86802.64e51036.15cf6a.0023.GAE@google.com> (raw)
In-Reply-To: <6ae78458.64e51036.15cf6a.0015.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] media: em28xx: clear dev->v4l2 on v4l2 init failure
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
If em28xx_v4l2_init() fails after registering the video devices (for
example in v4l2_mc_create_media_graph()), the unregister_dev error path
unregisters the devices and drops the initial v4l2_device reference
with v4l2_device_put(). However, it leaves dev->v4l2 pointing at the
em28xx_v4l2 structure.
If userspace still holds an open file handle to one of the video device
nodes, the structure stays alive through that reference. When the USB
device is later disconnected, em28xx_v4l2_fini() sees the non-NULL
dev->v4l2, treats the extension as fully initialized and drops the
initial reference a second time. This underflows the refcount and
em28xx_free_v4l2() frees struct em28xx_v4l2 while the file handle is
still open. When userspace closes it, v4l2_device_release() calls
media_device_unregister_entity() on a media entity embedded in the
freed structure, resulting in a slab use-after-free:
BUG: KASAN: slab-use-after-free in dev_dbg_obj+0x630/0x830
Read of size 4 at addr ffff888023601bd0 by task v4l_id/6384
Fix this by clearing dev->v4l2 in the error path after dropping the
initial reference, so that em28xx_v4l2_fini() returns early and does
not put the reference again.
Reported-by: syzbot+54648a6c1187a7ef46a6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=54648a6c1187a7ef46a6
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
drivers/media/usb/em28xx/em28xx-video.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 84424284d486..ec4ed2b0e5fd 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -3137,6 +3137,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
* v4l2_device refcount to zero.
*/
v4l2_device_put(&v4l2->v4l2_dev);
+ dev->v4l2 = NULL;
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2026-11-02 10:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 18:26 [syzbot] [media?] [usb?] KASAN: slab-use-after-free Read in dev_dbg_obj syzbot
2026-11-01 20:37 ` Forwarded: [PATCH] media: em28xx: fix v4l2 use-after-free after failed init syzbot
2026-11-02 10:37 ` syzbot [this message]
2026-11-02 12:03 ` Forwarded: [PATCH] media: em28xx: clear dev->v4l2 on v4l2 init failure syzbot
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=6ae86802.64e51036.15cf6a.0023.GAE@google.com \
--to=syzbot+54648a6c1187a7ef46a6@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®