From: Diego Fernando Mancera Gomez <diegomancera.dev@gmail.com>
To: mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
syzbot+1a7507a194fff09e5c44@syzkaller.appspotmail.com,
diegomancera.dev@gmail.com
Subject: [PATCH v3] media: em28xx: clear dev->v4l2 when v4l2 init fails
Date: Fri, 13 Nov 2026 08:53:59 -0600 [thread overview]
Message-ID: <20261113145359.65440-1-diegomancera.dev@gmail.com> (raw)
In-Reply-To: <CALruWrWRWRU84AkDocSnNMSRp+WQD5ic9G_3peE50BvQR5iGBg@mail.gmail.com>
In em28xx_v4l2_init(), if an error occurs after video_register_device()
succeeds, the unregister_dev error path unregisters the video devices and
drops the initial v4l2_dev reference, but leaves dev->v4l2 set.
An em28xx_v4l2_open() call already in progress (such as from v4l_id)
that blocked on dev->lock while em28xx_v4l2_init() held it will then
find dev->v4l2 still non-NULL and succeed on an unregistered node
instead of returning -ENODEV. When the device is later disconnected,
em28xx_v4l2_fini() also sees dev->v4l2 is still set and calls
v4l2_device_put() a second time, dropping the refcount to zero and
freeing v4l2 while v4l_id still holds it, causing a slab-use-after-free
in v4l2_open().
Fix this by clearing dev->v4l2 under dev->lock in the unregister_dev
error path of em28xx_v4l2_init().
Fixes: 288254383674 ("media: em28xx: use v4l2_device release callback")
Cc: stable@vger.kernel.org
Reported-by: syzbot+1a7507a194fff09e5c44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1a7507a194fff09e5c44
Signed-off-by: Diego Fernando Mancera Gomez <diegomancera.dev@gmail.com>
---
Changes in v3:
- Resend: v2 reached lore with the "diff --git" header line split in
two, so the Media CI robot could not apply it. No code changes.
Changes in v2:
- Drop the non-standard 'Assisted-by: Gemini' trailer that failed
checkpatch.
Note: compile-tested drivers/media/usb/em28xx/em28xx-video.o with
allmodconfig (no warnings); not runtime-tested locally against the
syzbot reproducer.
drivers/media/usb/em28xx/em28xx-video.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 84424284d486..f78325a41124 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -3129,6 +3129,12 @@ static int em28xx_v4l2_init(struct em28xx *dev)
vb2_video_unregister_device(&v4l2->vdev);
}
+ /*
+ * Clear dev->v4l2 to prevent an in-progress em28xx_v4l2_open() from
+ * succeeding on an unregistered node (returning -ENODEV instead) and
+ * to prevent em28xx_v4l2_fini() from tearing down the instance again.
+ */
+ dev->v4l2 = NULL;
mutex_unlock(&dev->lock);
/*
--
2.56.1
prev parent reply other threads:[~2026-11-13 14:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 4:21 [PATCH v2] media: em28xx: clear dev->v4l2 when v4l2 init fails Diego Fernando Mancera Gomez
2026-11-13 14:53 ` Diego Fernando Mancera Gomez [this message]
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=20261113145359.65440-1-diegomancera.dev@gmail.com \
--to=diegomancera.dev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+1a7507a194fff09e5c44@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