From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796110751; b=NK4xU0Z/2sEM3nL46tdf3eQpVs9c256dJ0M/HIRrW6bWvdpKW20HbflhJzLGTAg9cs2b zL8vWwANTmae6kXTnMm7ut/BsJBZQnSZvxEsuUmxB2/HXY5IGcoW/diyUMvrmQbpjkyu4 t+25zjR1vNtdeoArPPczn0QFEoFrX/o+pUdORhXij2MvW+8hcBWD9svWTizVqkDRl5rNv G4UbwkVmCE9PHf5PZW6nDGRAv3WqArdxkPmVgg8jPEv6x37Kh5YpMgqlznE6oS1/EJuhm SeuH5Iui2IqKbbxDX7/Pj4JlJaiTG1LJF49hBkmq4t1D1iV1yhC08r5wllE2dIOR0Tw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110751; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9kVd5SmVH9oGUQbsGOgBCft5nuhGVfL7QuBZP6XWMn8=; b=3mf7zKa7nCUs6s8SqbVU64AGAOkTKnWnFKEixDS8zoNJYmnmb5GB0YUW9mLsiAHXLBuc XRvkm/YFFCE8TGMRDnYQKElS+iDqOaUhCuhjYF6qyGrCSvC9SlH0TvVuw4uwwNGSTfqa7 0ugI7EFINUIs3hDkF7DOZ+NPKB49sbLBISd2QjKeFjVeY3Ig4HcXyM/UmJT//FtL1xne0 Pc2+wFlxOAz+4dKsoFUoNVzFYMaReSH+G6YqoVZvNBZ0dWz5RRBNNFsPtpaKppjTkd0h9 lPtX2KlD6KbBMK0isKjAn11sCcs0CUyWMniL/GT/2mVBkFBBRo49f/+it9Xnx0pNd+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cfhkCnHd; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9753B606A31A for ; Tue, 1 Dec 2026 07:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cfhkCnHd Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09F971F00893; Tue, 1 Dec 2026 07:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796110751; bh=9kVd5SmVH9oGUQbsGOgBCft5nuhGVfL7QuBZP6XWMn8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cfhkCnHdqysa8FCitlajcsKTjnzug3v6Miu0gm5We8ux0Jh4gskuNoEfV20VOqViL p0a05s1kkX79Wlc2tPwXrGgaTGf6hcoIr5gPzUECihnAR1hEJJWSTN2g4GEeu3YW4F IzTMiPbqlK7NOIfacWCYJ5yIiaxiPRLKLD675GKLJOOC6PaWrB/dPsJdiNIrOkS9cT 5kWMN9XUgsukguKPl1IR0EdhdNpibzBqdqe2vuTEEEx1dB0bb+Xm+9CMiAeOIo+PU7 UjihdDT5eIYTD8rOWmHVwDbzCLz/xdZErWpG2sbs+Mqn2TXDJce8HnZVkvPbUpus3C 47O3K5/wkyVzw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] usb: gadget: uvc: cap isoc payload at request size Reply-To: sashiko-reviews@lists.linux.dev To: "Keisuke Tsukuda" Cc: =?utf-8?b?bGludXgtdXNiQHZnZXIua2VybmVsLm9yZw==?= In-Reply-To: <20261201072659.94982-1-tkdkei@outlook.jp> References: <20261201072659.94982-1-tkdkei@outlook.jp> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 07:39:10 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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; > } > =20 > + /* Buffer payload size may predate the current request size. */ > + if (!is_bulk) > + buf->req_payload_size =3D min(buf->req_payload_size, > + video->req_size); > + > video->encode(req, video, buf); > =20 > 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=3D1), both video->reqs_per_frame and video->max_req_size are 0, so uvc_buffer_prepare() sets buf->req_payload_size =3D 0. Once streaming starts, min(0, video->req_size) stays 0; uvc_video_encode_isoc() then subtracts the header length from int len =3D 0, and uvc_video_encode_data() casts the negative len to unsign= ed 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 n= ew 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_fram= e, 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_reques= ts() 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 interv= al via VIDIOC_S_PARM and then calls VIDIOC_STREAMON, uvc_video_prep_requests() computes nreq =3D 0 and divides by nreq: drivers/usb/gadget/function/uvc_video.c:uvc_video_prep_requests() { ... nreq =3D DIV_ROUND_UP(video->interval, interval_duration); header_size =3D nreq * UVCG_REQUEST_HEADER_LEN; req_size =3D 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 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201072659.9498= 2-1-tkdkei@outlook.jp?part=3D1