mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: syzbot <syzbot+b2391895514ed9ef4a8e@syzkaller.appspotmail.com>
Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: KASAN: use-after-free Read in v4l2_fh_open
Date: Sun,  3 Mar 2024 09:43:51 +0800	[thread overview]
Message-ID: <20240303014351.1274-1-hdanton@sina.com> (raw)
In-Reply-To: <00000000000017937c05bb617f1d@google.com>

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);
 
@@ -2376,10 +2381,17 @@ static const struct v4l2_ioctl_ops video
 #endif
 };
 
+static void em28xx_video_device_release(struct video_device *vd)
+{
+	struct em28xx_v4l2 *v4l2 = container_of(vd, struct em28xx_v4l2, vdev);
+
+	kref_put(&v4l2->ref, em28xx_free_v4l2);
+}
+
 static const struct video_device em28xx_video_template = {
 	.fops		= &em28xx_v4l_fops,
 	.ioctl_ops	= &video_ioctl_ops,
-	.release	= video_device_release_empty,
+	.release	= em28xx_video_device_release,
 	.tvnorms	= V4L2_STD_ALL,
 };
 
@@ -2788,6 +2800,7 @@ static int em28xx_v4l2_init(struct em28x
 			"unable to register video device (error=%i).\n", ret);
 		goto unregister_dev;
 	}
+	kref_get(&v4l2->ref); /* put by video_unregister_device() */
 
 	/* Allocate and fill vbi video_device struct */
 	if (em28xx_vbi_supported(dev) == 1) {
--

  parent reply	other threads:[~2024-03-03  1:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 15:18 syzbot
2021-05-04 21:28 ` SyzScope
2024-03-02 10:56 ` Hillf Danton
2024-03-02 13:02   ` [syzbot] [usb?] [media?] " syzbot
2024-03-02 23:07 ` Hillf Danton
2024-03-02 23:39   ` [syzbot] [usb?] [media?] " syzbot
2024-03-03  1:43 ` Hillf Danton [this message]
2024-03-03  2:55   ` syzbot
2024-03-02  8:08 xingwei lee

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=20240303014351.1274-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+b2391895514ed9ef4a8e@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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®