All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH 08/19] usb: gadget: uvc: fix oops on a premature STREAMON
Date: Tue, 27 Oct 2026 15:22:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-186826@kernel.org> (raw)
In-Reply-To: <20261027-llm-usb-v1-8-b9751ddb9c7c@linuxfoundation.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: gadget: uvc: racy and incomplete ep->desc check in uvcg_video_enable()
--

commit c0162971ecaec9497fd415372ef37c6e328eefc7
Author: Josef Bacik <josef@toxicpanda.com>

usb: gadget: uvc: fix oops on a premature STREAMON

This commit adds a NULL check on video->ep->desc in uvcg_video_enable() to
return -ENODEV if userspace issues VIDIOC_STREAMON before the host has
selected the streaming alternate setting.

> diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> index 9ba09118bb74a..2a56536c34817 100644
> --- a/drivers/usb/gadget/function/uvc_video.c
> +++ b/drivers/usb/gadget/function/uvc_video.c
> @@ -770,6 +770,10 @@ int uvcg_video_enable(struct uvc_video *video)
>  		return -ENODEV;
>  	}
>  
> +	/* Set while the host has selected the streaming alternate setting. */
> +	if (!video->ep->desc)
> +		return -ENODEV;

[Severity: High]
Is checking video->ep->desc without synchronization sufficient here to prevent
races and ensure the endpoint is ready for streaming?

uvc_v4l2_streamon() -> uvcg_video_enable() runs in process context holding
only video->mutex, whereas uvc_function_set_alt() and uvc_function_disable()
in drivers/usb/gadget/function/f_uvc.c run under cdev->lock without
video->mutex:

drivers/usb/gadget/function/f_uvc.c:uvc_function_disable() {
	...
	uvc->state = UVC_STATE_DISCONNECTED;

	usb_ep_disable(uvc->video.ep);
	...
}

drivers/usb/gadget/function/f_uvc.c:uvc_function_set_alt() {
	...
		usb_ep_disable(uvc->video.ep);

		ret = config_ep_by_speed(f->config->cdev->gadget,
				&(uvc->func), uvc->video.ep);
		if (ret)
			return ret;
		usb_ep_enable(uvc->video.ep);

		uvc->video.max_req_size = uvc->video.ep->maxpacket
			* max_t(unsigned int, uvc->video.ep->maxburst, 1)
			* (uvc->video.ep->mult);
	...
}

After uvcg_video_enable() checks video->ep->desc and calls
uvcg_queue_enable(), uvc_video_alloc_requests() -> uvc_video_prep_requests()
in drivers/usb/gadget/function/uvc_video.c reloads and dereferences
video->ep->desc again:

drivers/usb/gadget/function/uvc_video.c:uvc_video_prep_requests() {
	...
	max_req_size = video->max_req_size;

	if (!usb_endpoint_xfer_isoc(video->ep->desc)) {
		video->req_size = max_req_size;
		video->reqs_per_frame = video->uvc_num_requests =
			DIV_ROUND_UP(video->imagesize, max_req_size);

		return;
	}

	interval_duration = 1 << (video->ep->desc->bInterval - 1);
	...
}

Could this leave several issues open:

1. If uvc_function_disable() or uvc_function_set_alt() calls
   usb_ep_disable(uvc->video.ep) between the check in uvcg_video_enable() and
   uvc_video_prep_requests(), can a UDC driver that clears ep->desc on disable
   (such as dwc3) still trigger a NULL pointer dereference in
   uvc_video_prep_requests()?

2. In uvc_function_set_alt(), config_ep_by_speed() sets uvc->video.ep->desc
   before usb_ep_enable() and before uvc->video.max_req_size is calculated
   (and config_ep_by_speed_and_alt() can also fail after assigning _ep->desc).
   If a premature streamon runs in that window while video->max_req_size is
   still 0, can uvc_video_prep_requests() divide by zero on bulk endpoints or
   leave video->req_size as 0 (underflowing video->req_size -
   UVCG_REQUEST_HEADER_LEN in uvc_video_alloc_requests()) on isochronous
   endpoints?

3. Since usb_ep_disable() in drivers/usb/gadget/udc/core.c only clears
   ep->enabled and several UDC drivers (such as dwc2 and cdnsp) do not clear
   ep->desc in their disable callback, won't video->ep->desc remain non-NULL
   after streamoff or disconnect on those controllers, allowing a subsequent
   premature streamon to bypass this check and set uvc->state to
   UVC_STATE_STREAMING while the endpoint is disabled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027-llm-usb-v1-0-b9751ddb9c7c@linuxfoundation.org?part=8

  reply	other threads:[~2026-10-27 15:22 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 14:57 [PATCH 00/19] USB: a bunch of llm-found fixes Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 01/19] usb: core: sysfs: take the port lock to read the BOS Greg Kroah-Hartman
2026-10-27 15:10   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 02/19] USB: core: signal the end of an sg request last Greg Kroah-Hartman
2026-10-27 15:04   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 03/19] usbip: vudc: free the unlink item if the send fails Greg Kroah-Hartman
2026-10-27 15:09   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 04/19] usb: host: oxu210hp-hcd: fix oxu_qh_alloc() deadlock Greg Kroah-Hartman
2026-10-27 15:06   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 05/19] usb: cdns3: switch the role unlocked on resume Greg Kroah-Hartman
2026-10-27 15:27   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 06/19] usb: gadget: snps_udc_plat: lock out the interrupt Greg Kroah-Hartman
2026-10-27 15:05   ` sashiko-bot
2026-10-27 18:17   ` Herve Codina
2026-10-27 14:57 ` [PATCH 07/19] usb: gadget: bdc: the resume callback is optional Greg Kroah-Hartman
2026-10-27 15:06   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 08/19] usb: gadget: uvc: fix oops on a premature STREAMON Greg Kroah-Hartman
2026-10-27 15:22   ` sashiko-bot [this message]
2026-10-27 14:57 ` [PATCH 09/19] usb: gadget: f_fs: let the request keep its fence Greg Kroah-Hartman
2026-10-27 15:15   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 10/19] usb: host: ehci-orion: fix the probe without DT Greg Kroah-Hartman
2026-10-27 15:09   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 11/19] usb: typec: tcpm: don't wait for the VDM discovery work Greg Kroah-Hartman
2026-10-27 15:18   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 12/19] usb: typec: tcpci: don't act on unread alerts Greg Kroah-Hartman
2026-10-27 15:12   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 13/19] usb: typec: anx7411: zero on-stack alt mode descriptors Greg Kroah-Hartman
2026-10-27 15:10   ` sashiko-bot
2026-10-28 16:20   ` Benson Leung
2026-10-27 14:57 ` [PATCH 14/19] usb: typec: mux: it5205: fix oops on accessory modes Greg Kroah-Hartman
2026-10-27 15:13   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 15/19] usb: typec: mux: tusb1046: " Greg Kroah-Hartman
2026-10-27 15:13   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 16/19] usb: renesas_usbhs: link URBs with interrupts disabled Greg Kroah-Hartman
2026-10-27 15:23   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 17/19] usb: renesas_usbhs: unlink the URB if it is not queued Greg Kroah-Hartman
2026-10-27 15:27   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 18/19] usb: isp1760: wait for the TT clear in endpoint_disable Greg Kroah-Hartman
2026-10-27 15:21   ` Rui Miguel Silva
2026-10-27 15:28   ` sashiko-bot
2026-10-27 14:57 ` [PATCH 19/19] usb: dwc2: " Greg Kroah-Hartman
2026-10-27 15:37   ` sashiko-bot

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=sashiko-outbox-186826@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.