Forwarded: [PATCH] media: em28xx: fix v4l2 use-after-free after failed init

From: syzbot

Date: Sun Nov 01 2026 - 15:37:15 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx.

***

Subject: [PATCH] media: em28xx: fix v4l2 use-after-free after failed init
Author: drifabdelmalekmohamedsaid@xxxxxxxxx

#syz test
---
drivers/media/usb/em28xx/em28xx-video.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 84424284d486..924a3f7977c9 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -2414,7 +2414,7 @@ static int em28xx_v4l2_open(struct file *filp)
*/
static int em28xx_v4l2_fini(struct em28xx *dev)
{
- struct em28xx_v4l2 *v4l2 = dev->v4l2;
+ struct em28xx_v4l2 *v4l2;

if (dev->is_audio_only) {
/* Shouldn't initialize IR for this interface */
@@ -2426,13 +2426,17 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
return 0;
}

- if (!v4l2)
- return 0;
-
dev_info(&dev->intf->dev, "Closing video extension\n");

mutex_lock(&dev->lock);

+ /* matches em28xx_v4l2_init error paths */
+ v4l2 = dev->v4l2;
+ if (!v4l2){
+ mutex_unlock(&dev->lock);
+ return 0;
+ }
+
v4l2_device_disconnect(&v4l2->v4l2_dev);

em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
@@ -3129,6 +3133,9 @@ static int em28xx_v4l2_init(struct em28xx *dev)
vb2_video_unregister_device(&v4l2->vdev);
}

+ /* matches check in em28xx_v4l2_fini (under the same lock) */
+ dev->v4l2 = NULL;
+
mutex_unlock(&dev->lock);

/*
--
2.43.0