From: Deepanshu Kartikey <kartikey406@gmail.com>
To: mchehab@kernel.org, sakari.ailus@linux.intel.com,
laurent.pinchart@ideasonboard.com, hverkuil@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Deepanshu Kartikey <kartikey406@gmail.com>,
syzbot+54648a6c1187a7ef46a6@syzkaller.appspotmail.com
Subject: [PATCH 1/2] media: em28xx: clear dev->v4l2 on v4l2 init failure
Date: Mon, 2 Nov 2026 19:44:38 +0530 [thread overview]
Message-ID: <20261102141439.13505-2-kartikey406@gmail.com> (raw)
In-Reply-To: <20261102141439.13505-1-kartikey406@gmail.com>
If em28xx_v4l2_init() fails after registering the video devices (for
example in v4l2_mc_create_media_graph()), the unregister_dev error path
drops the initial v4l2_device reference but leaves dev->v4l2 set.
If userspace still holds an open file handle to a video node, the
structure stays alive. On USB disconnect, em28xx_v4l2_fini() sees the
non-NULL dev->v4l2 and drops the initial reference a second time. The
refcount underflows, em28xx_free_v4l2() frees struct em28xx_v4l2, and
the later close() makes v4l2_device_release() touch a media entity in
freed memory:
BUG: KASAN: slab-use-after-free in dev_dbg_obj+0x630/0x830
Read of size 4 at addr ffff888023601bd0 by task v4l_id/6384
Clear dev->v4l2 in the error path after dropping the initial reference,
so that em28xx_v4l2_fini() returns early and does not put it again.
Fixes: 288254383674 ("media: em28xx: use v4l2_device release callback")
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 14:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 14:14 [PATCH 0/2] media: fix em28xx v4l2 init failure refcount underflow and a media core unregister race Deepanshu Kartikey
2026-11-02 14:14 ` Deepanshu Kartikey [this message]
2026-11-02 14:14 ` [PATCH 2/2] media: mc: fix race in media_device_unregister_entity() Deepanshu Kartikey
2026-11-02 15:13 ` laurent.pinchart
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=20261102141439.13505-2-kartikey406@gmail.com \
--to=kartikey406@gmail.com \
--cc=hverkuil@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=syzbot+54648a6c1187a7ef46a6@syzkaller.appspotmail.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®