From: sashiko-bot@kernel.org
To: "Xu Yang" <xu.yang_2@oss.nxp.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v2 2/2] usb: gadget: uvc: refactor video cleanup into uvcg_video_deinit()
Date: Wed, 23 Sep 2026 10:51:55 +0000 [thread overview]
Message-ID: <20260923105156.5DC731F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923-usb-uvc-fixes-v2-2-844e04a4a4b7@nxp.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: gadget: uvc: missing mutex in unbind causes UAF in uvcg_video_deinit()
--
commit 5b750200592f725e55689646ba5d3a79912818ba
Author: Xu Yang <xu.yang_2@nxp.com>
usb: gadget: uvc: refactor video cleanup into uvcg_video_deinit()
This commit consolidates the teardown logic for the UVC gadget's async
workqueue and kworker into a new uvcg_video_deinit() helper to prevent
resource leaks during bind failures and unbind. It also changes the unbind
sequence to tear down these resources after unregistering the V4L2 device.
> diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
> index a4fb2790f4ffe..fa2f9d0e4ce0b 100644
> --- a/drivers/usb/gadget/function/f_uvc.c
> +++ b/drivers/usb/gadget/function/f_uvc.c
[ ... ]
> @@ -1048,6 +1044,7 @@ static void uvc_function_unbind(struct usb_configuration *c,
>
> device_remove_file(&uvc->vdev.dev, &dev_attr_function_name);
> video_unregister_device(&uvc->vdev);
> + uvcg_video_deinit(video);
[Severity: High]
Can this cause a use-after-free if an ioctl is currently executing?
When uvc_function_unbind() calls video_unregister_device(), it clears
the registered flag but does not wait for active ioctls to complete. Since
uvc_function_unbind() does not hold video->mutex, an in-flight
VIDIOC_STREAMON ioctl could concurrently be executing uvcg_video_enable().
Meanwhile, uvc_function_unbind() proceeds to call uvcg_video_deinit()
without any locks.
> v4l2_device_unregister(&uvc->v4l2_dev);
>
> scoped_guard(mutex, &uvc->lock)
> diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> index 9ba09118bb74a..002afca9141ee 100644
> --- a/drivers/usb/gadget/function/uvc_video.c
> +++ b/drivers/usb/gadget/function/uvc_video.c
[ ... ]
> @@ -841,3 +841,18 @@ int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc)
> return uvcg_queue_init(&video->queue, uvc->v4l2_dev.dev->parent,
> V4L2_BUF_TYPE_VIDEO_OUTPUT, &video->mutex);
> }
> +
> +void uvcg_video_deinit(struct uvc_video *video)
> +{
> + kthread_cancel_work_sync(&video->hw_submit);
> +
> + if (!IS_ERR_OR_NULL(video->kworker)) {
> + kthread_destroy_worker(video->kworker);
> + video->kworker = NULL;
> + }
[Severity: High]
Does destroying the kworker here locklessly open a race window?
If uvcg_video_enable() is executing concurrently under video->mutex, it calls
kthread_queue_work(video->kworker, &video->hw_submit).
If uvcg_video_deinit() frees video->kworker before the ioctl finishes,
will uvcg_video_enable() dereference freed memory and crash the kernel?
> +
> + if (video->async_wq) {
> + destroy_workqueue(video->async_wq);
> + video->async_wq = NULL;
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260923-usb-uvc-fixes-v2-0-844e04a4a4b7@nxp.com?part=2
prev parent reply other threads:[~2026-09-23 10:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 10:39 [PATCH v2 0/2] usb: gadget: uvc: fix resource leak on video->async_wq and video->kworker Xu Yang
2026-09-23 10:39 ` [PATCH v2 1/2] usb: gadget: uvc: replace mutex lock/unlock with scoped_guard in uvc_function_bind() Xu Yang
2026-09-23 10:45 ` sashiko-bot
2026-09-23 10:39 ` [PATCH v2 2/2] usb: gadget: uvc: refactor video cleanup into uvcg_video_deinit() Xu Yang
2026-09-23 10:51 ` sashiko-bot [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=20260923105156.5DC731F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xu.yang_2@oss.nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.