Re: KASAN: use-after-free Read in v4l2_fh_open

From: Hillf Danton
Date: Sat Mar 02 2024 - 05:56:45 EST


On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
>
> HEAD commit: 291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS;

+ if (!dev->v4l2) {
+ mutex_unlock(&dev->lock);
+ return -ENODEV;
+ }
ret = v4l2_fh_open(filp);
if (ret) {
dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
return ret;
}

+ v4l2 = dev->v4l2;
if (v4l2->users == 0) {
em28xx_set_mode(dev, EM28XX_ANALOG_MODE);

--