From: sashiko-bot@kernel.org
To: "Keisuke Tsukuda" <tkdkei@outlook.jp>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] usb: gadget: uvc: cap isoc payload at request size
Date: Tue, 01 Dec 2026 07:39:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-242783@kernel.org> (raw)
In-Reply-To: <20261201072659.94982-1-tkdkei@outlook.jp>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: gadget: uvc: min() clamp in uvcg_video_pump() leaves
payload 0 or stale
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] usb: gadget: uvc: division by zero in
uvc_video_prep_requests() [1]
--
commit eb52cb730fce5dcb9e4c868a1cd37f6e22f56c05
Author: Keisuke Tsukuda <tkdkei@outlook.jp>
usb: gadget: uvc: cap isoc payload at request size
This commit caps buf->req_payload_size at video->req_size for isochronous
transfers in uvcg_video_pump() before invoking video->encode().
> diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> index 002afca9141ee..7d05c5f1f769e 100644
> --- a/drivers/usb/gadget/function/uvc_video.c
> +++ b/drivers/usb/gadget/function/uvc_video.c
> @@ -651,6 +651,11 @@ static void uvcg_video_pump(struct work_struct *work)
> break;
> }
>
> + /* Buffer payload size may predate the current request size. */
> + if (!is_bulk)
> + buf->req_payload_size = min(buf->req_payload_size,
> + video->req_size);
> +
> video->encode(req, video, buf);
>
> spin_unlock_irqrestore(&queue->irqlock, flags);
[Severity: High]
Can clamping downward with min() leave buf->req_payload_size at 0 or stuck at
a previous stream's smaller request size?
video->max_req_size is only initialized in uvc_function_set_alt() when the
host selects alternate setting 1. If userspace calls VIDIOC_QBUF before the
first SET_INTERFACE(alt=1), both video->reqs_per_frame and
video->max_req_size are 0, so uvc_buffer_prepare() sets
buf->req_payload_size = 0. Once streaming starts, min(0, video->req_size)
stays 0; uvc_video_encode_isoc() then subtracts the header length from
int len = 0, and uvc_video_encode_data() casts the negative len to unsigned
int in min_t(), copying the entire frame into the video->req_size request
buffer and overflowing the heap buffer (or underflowing unsigned int len in
uvc_video_encode_isoc_sg()).
Similarly, because uvcg_video_disable() does not reset video->reqs_per_frame
or video->req_size on VIDIOC_STREAMOFF, buffers queued before the next
VIDIOC_STREAMON are prepared against the old stream's parameters. If the new
stream uses a larger video->req_size, min() keeps buf->req_payload_size
clamped to the previous stream's smaller request size; and for compressed
frames queued before the first VIDIOC_STREAMON, min() bounds the payload to
video->req_size rather than dividing buf->bytesused across
video->reqs_per_frame.
Recomputing buf->req_payload_size from buf->bytesused, video->reqs_per_frame,
and video->req_size when encoding starts would handle both pre-stream
queueing and stream transitions.
[Severity: Critical]
This problem wasn't introduced by this patch, but can uvc_video_prep_requests()
divide by zero when computing the request size [1]?
uvc_v4l2_s_parm() writes the user-supplied frame interval directly into
video->interval without checking for zero. If userspace sets a zero interval
via VIDIOC_S_PARM and then calls VIDIOC_STREAMON, uvc_video_prep_requests()
computes nreq = 0 and divides by nreq:
drivers/usb/gadget/function/uvc_video.c:uvc_video_prep_requests() {
...
nreq = DIV_ROUND_UP(video->interval, interval_duration);
header_size = nreq * UVCG_REQUEST_HEADER_LEN;
req_size = DIV_ROUND_UP(video->imagesize + header_size, nreq);
...
}
This triggers a divide-by-zero oops in kernel mode.
[1] https://sashiko.dev/#/bug/linux-51fdd0db-93bb-4ef0-9a91-e82a361b6db7
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201072659.94982-1-tkdkei@outlook.jp?part=1
prev parent reply other threads:[~2026-12-01 7:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 7:27 [PATCH] usb: gadget: uvc: cap isoc payload at request size Keisuke Tsukuda
2026-12-01 7:39 ` 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=sashiko-outbox-242783@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tkdkei@outlook.jp \
/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.