mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liu Chao <liuc63@xiaopeng.com>
To: gregkh@linuxfoundation.org
Cc: laurent.pinchart@ideasonboard.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	liuwb@xiaopeng.com, Liu Chao <liuc63@xiaopeng.com>
Subject: [PATCH] usb: gadget: uvc: reject zero interval in uvc_v4l2_s_parm()
Date: Thu, 17 Sep 2026 18:31:22 +0800	[thread overview]
Message-ID: <20260917103122.3045458-1-liuc63@xiaopeng.com> (raw)

v4l2_fraction_to_interval() returns 0 when the caller passes
numerator == 0 with a non-zero denominator.  If this zero value is
stored in video->interval, the isoc path in uvc_video_prep_requests()
computes:

    nreq = DIV_ROUND_UP(video->interval, interval_duration);  /* 0 */
    req_size = DIV_ROUND_UP(video->imagesize + header_size, nreq);

The second DIV_ROUND_UP divides by zero, crashing the kernel.

Any local process that can open the UVC gadget's /dev/videoN and issue
VIDIOC_S_PARM with timeperframe.numerator = 0 followed by
VIDIOC_STREAMON triggers this immediately.

Reject a zero interval in uvc_v4l2_s_parm() before it is stored.

Fixes: 0525210c9840 ("usb: gadget: uvc: add VIDIOC_S_PARM and VIDIOC_G_PARM support")
Cc: stable@vger.kernel.org
Reviewed-by: Weibin Liu <liuwb@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
 drivers/usb/gadget/function/uvc_v4l2.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index dfa0521a2..e9b9288c5 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -368,6 +368,11 @@ static int uvc_v4l2_s_parm(struct file *file, void *fh,
 	video->interval = v4l2_fraction_to_interval(timeperframe.numerator,
 						    timeperframe.denominator);
 
+	if (!video->interval) {
+		uvcg_dbg(&uvc->func, "Invalid zero interval, rejecting\n");
+		return -EINVAL;
+	}
+
 	uvcg_dbg(&uvc->func, "Setting frame interval to %u/%u (%u)\n",
 		 timeperframe.numerator, timeperframe.denominator,
 		 video->interval);
-- 
2.50.1


                 reply	other threads:[~2026-09-17 10:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260917103122.3045458-1-liuc63@xiaopeng.com \
    --to=liuc63@xiaopeng.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=liuwb@xiaopeng.com \
    --cc=stable@vger.kernel.org \
    /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®