Re: [PATCH 1/2] media: em28xx: clear dev->v4l2 on v4l2 init failure

From: Deepanshu Kartikey

Date: Sun Nov 15 2026 - 08:38:07 EST


On Mon, Nov 2, 2026 at 7:45 PM Deepanshu Kartikey <kartikey406@xxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspot.com/bug?extid=54648a6c1187a7ef46a6
> Signed-off-by: Deepanshu Kartikey <kartikey406@xxxxxxxxx>
> ---
> 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
>

Gentle Reminder, Please let me know the status of this patch.

Thanks

Deepanshu