From: Nguyen Duy Nhat Anh <neganhat@gmail.com>
To: mchehab@kernel.org
Cc: llinux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Nguyen Duy Nhat Anh <neganhat@gmail.com>,
syzbot+809dfc586f33fc44b6ac@syzkaller.appspotmail.com
Subject: [PATCH 2/3] media: em28xx: clear v4l2_dev.mdev on media device unregister
Date: Fri, 23 Oct 2026 02:34:51 +0700 [thread overview]
Message-ID: <20261022193452.12966-1-neganhat@gmail.com> (raw)
In-Reply-To: <20261022193159.12713-1-neganhat@gmail.com>
em28xx_unregister_media_device() frees dev->media_dev, but leaves
v4l2_dev.mdev holding a dangling pointer to the freed allocation.
When a process closes a video node after disconnect, v4l2_release() calls
v4l2_device_supports_requests(), dereferencing v4l2_dev.mdev and causing a
KASAN slab-use-after-free read.
Fix this by setting v4l2_dev.mdev to NULL in em28xx_unregister_media_device()
prior to calling kfree(dev->media_dev).
Reported-by: syzbot+809dfc586f33fc44b6ac@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=809dfc586f33fc44b6ac
Signed-off-by: Nguyen Duy Nhat Anh <neganhat@gmail.com>
---
drivers/media/usb/em28xx/em28xx-cards.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 8440eafad44e..40fec8b025e8 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -3776,6 +3776,8 @@ static void em28xx_unregister_media_device(struct em28xx *dev)
if (dev->media_dev) {
media_device_unregister(dev->media_dev);
media_device_cleanup(dev->media_dev);
+ if (dev->v4l2)
+ dev->v4l2->v4l2_dev.mdev = NULL;
kfree(dev->media_dev);
dev->media_dev = NULL;
}
--
2.55.0
next prev parent reply other threads:[~2026-10-22 19:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 19:31 [PATCH 0/3] media: em28xx: fix multiple disconnect races and UAFs Nguyen Duy Nhat Anh
2026-10-22 19:33 ` [PATCH 1/3] media: em28xx: check dev->disconnected in em28xx_v4l2_open() Nguyen Duy Nhat Anh
2026-10-22 19:34 ` Nguyen Duy Nhat Anh [this message]
2026-10-22 19:35 ` [PATCH 3/3] media: em28xx: fix refcount underflow in em28xx_free_v4l2() Nguyen Duy Nhat Anh
2026-10-22 19:46 [PATCH 0/3] media: em28xx: fix multiple disconnect races and UAFs Nguyen Duy Nhat Anh
2026-10-22 19:48 ` [PATCH 1/3] media: em28xx: check dev->disconnected in em28xx_v4l2_open() Nguyen Duy Nhat Anh
2026-10-22 19:48 ` [PATCH 2/3] media: em28xx: clear v4l2_dev.mdev on media device unregister Nguyen Duy Nhat Anh
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=20261022193452.12966-1-neganhat@gmail.com \
--to=neganhat@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llinux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=syzbot+809dfc586f33fc44b6ac@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®