From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Nguyen Duy Nhat Anh <neganhat@gmail.com>, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+809dfc586f33fc44b6ac@syzkaller.appspotmail.com
Subject: Re: [PATCH 3/3] media: em28xx: fix refcount underflow in em28xx_free_v4l2()
Date: Thu, 12 Nov 2026 15:14:09 +0100 [thread overview]
Message-ID: <72684fa2-57d9-4e92-8bff-9213a27215b8@kernel.org> (raw)
In-Reply-To: <20261022194901.14302-3-neganhat@gmail.com>
On 22/10/2026 21:49, Nguyen Duy Nhat Anh wrote:
> em28xx_free_v4l2() is registered as the v4l2_dev release callback, invoked
> when v4l2_dev's reference count drops to zero.
>
> Calling v4l2_device_unregister() from inside this callback causes an extra
> call to v4l2_device_put() on a zero reference count, triggering a refcount_t
> underflow (0 -> -1) and a kernel BUG in lib/refcount.c.
Huh? v4l2_device_unregister doesn't call v4l2_device_put AFAICS.
This doesn't sounds right.
Regards,
Hans
>
> Fix this by removing v4l2_device_unregister() from em28xx_free_v4l2() and
> calling it in em28xx_v4l2_fini() during teardown instead.
>
> Reported-by: syzbot+809dfc586f33fc44b6ac@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=809dfc586f33fc44b6ac
> Signed-off-by: Nguyen Duy Nhat Anh <neganhat@gmail.com>
> ---
> drivers/media/usb/em28xx/em28xx-video.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
> index d653341ffd16..45b62655ca3b 100644
> --- a/drivers/media/usb/em28xx/em28xx-video.c
> +++ b/drivers/media/usb/em28xx/em28xx-video.c
> @@ -2332,7 +2332,6 @@ static void em28xx_free_v4l2(struct v4l2_device *v4l2_dev)
> struct em28xx *dev = v4l2->dev;
>
> v4l2_ctrl_handler_free(&v4l2->ctrl_handler);
> - v4l2_device_unregister(v4l2_dev);
> dev->v4l2 = NULL;
> kfree(v4l2);
> kref_put(&dev->ref, em28xx_free_device);
> @@ -2462,7 +2461,7 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
> * The em28xx_free_v4l2() release callback will be invoked once all
> * userspace file handles to the video device nodes are closed.
> */
> - v4l2_device_put(&v4l2->v4l2_dev);
> + v4l2_device_unregister(&v4l2->v4l2_dev);
>
> return 0;
> }
next prev parent reply other threads:[~2026-11-12 14:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 19:46 [PATCH 0/3] media: em28xx: fix multiple disconnect races and UAFs Nguyen Duy Nhat Anh
2026-10-22 19:48 ` [PATCH 1/3] media: em28xx: check dev->disconnected in em28xx_v4l2_open() Nguyen Duy Nhat Anh
2026-10-22 19:48 ` [PATCH 2/3] media: em28xx: clear v4l2_dev.mdev on media device unregister Nguyen Duy Nhat Anh
2026-10-22 19:49 ` [PATCH 3/3] media: em28xx: fix refcount underflow in em28xx_free_v4l2() Nguyen Duy Nhat Anh
2026-11-12 14:14 ` Hans Verkuil [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-10-22 19:31 [PATCH 0/3] media: em28xx: fix multiple disconnect races and UAFs Nguyen Duy Nhat Anh
2026-10-22 19:35 ` [PATCH 3/3] media: em28xx: fix refcount underflow in em28xx_free_v4l2() Nguyen Duy Nhat Anh
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=72684fa2-57d9-4e92-8bff-9213a27215b8@kernel.org \
--to=hverkuil+cisco@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=neganhat@gmail.com \
--cc=syzbot+809dfc586f33fc44b6ac@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
all inboxes | Powered by JetHome®