From: Natasha Klaus <natalie.klaus@runtimeverification.com>
To: noambs2999@gmail.com
Cc: ribalda@chromium.org, laurent.pinchart@ideasonboard.com,
hansg@kernel.org, mchehab@kernel.org,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Natasha Klaus <natalie.klaus@runtimeverification.com>
Subject: Re: [PATCH v2] media: uvcvideo: Fix integer overflow in frame buffer size calculation
Date: Tue, 18 Aug 2026 09:45:11 +0300 [thread overview]
Message-ID: <20260818064511.104024-1-natalie.klaus@runtimeverification.com> (raw)
In-Reply-To: <20260812103251.18309-1-noambs2999@gmail.com>
On Wed, Aug 12, 2026 at 01:32:51PM +0300, Noam Ben Shimon wrote:
> + if (!(format->flags & UVC_FMT_FLAG_COMPRESSED)) {
> + u64 bufsize;
> +
> + bufsize = ((u64)format->bpp * frame->wWidth * frame->wHeight) >> 3;
> + if (bufsize > U32_MAX) {
> + uvc_dbg(dev, DESCR,
> + "device %d videostreaming interface %d FRAME %u: computed buffer size overflows\n",
> + dev->udev->devnum,
> + alts->desc.bInterfaceNumber,
> + frame->bFrameIndex);
> + return -EINVAL;
> + }
> +
> + frame->dwMaxVideoFrameBufferSize = bufsize;
> + }
Ricardo asked me to look at this. I had been looking at the same expression
independently, so I checked your numbers and the surrounding behaviour
rather than only the diff.
Both examples in the commit message reproduce exactly. 32 bpp at
16384x4096 gives 4026531840 against a true 268435456, and 16 bpp at
16384x16384 gives 0 against 536870912.
One case I would add to the commit message, because it is the strongest
argument for rejecting rather than only widening. bpp=32 at 32768x32768
is exactly 2^35, so the 64-bit quotient is exactly 2^32. A bare (u64)
cast without your check would store 0 there, which is the same failure
the patch removes. Your check catches it.
I also checked when the check can fire at all. For bpp <= 8 the threshold
is unreachable given the u16 field limits, and it does not need to be
reachable: the largest possible result at bpp=8 is 4294836225, which
still fits in u32. So the check fires exactly where it is needed and
nowhere else. That seemed worth confirming rather than assuming.
My one question is about the error path rather than the arithmetic.
uvc_parse_frame() has a single caller, and -EINVAL propagates further
than I first expected:
uvc_driver.c:495 return ret, so the whole format is abandoned
uvc_driver.c:745 goto error, so remaining formats are never parsed
uvc_driver.c:788 usb_driver_release_interface() and uvc_stream_delete(),
so the streaming interface never reaches dev->streams
uvc_driver.c:1004 the uvc_parse_streaming() return value is discarded,
so probe continues and succeeds
uvc_driver.c:2135 "No streaming interface found for terminal %u"
So one malformed frame descriptor costs the entire streaming interface,
not just that frame, and probe still succeeds. On a single-interface
webcam that means the device binds with no /dev/videoN, and the only
explanation is the uvc_dbg line above, which sits behind a debug bit
that is off by default.
I do not think this is a practical regression risk, since no plausible
device reaches 2^35, and the surrounding function is otherwise built
around repairing bad descriptors rather than rejecting them. What
bothers me is the silence: a user who does trip it sees a device that
binds and produces nothing, with no logged reason. Two ways to address
that:
- dev_warn() instead of uvc_dbg(), so the reason is visible without a
debug build
- skip only that frame descriptor and continue, rather than failing
the format
Either would satisfy me. If you and the maintainers would rather keep
-EINVAL with uvc_dbg as it stands, I have no objection to that either,
and you are welcome to add
Reviewed-by: Natasha Klaus <natalie.klaus@runtimeverification.com>
to v2 as it is.
Separately, and explicitly not an objection to this patch: a zero
dwMaxVideoFrameBufferSize stays reachable from the other end. Any zero
operand, or any product below 8, gives 0 after the shift, and bpp=0 does
reach the computation on uncompressed formats. Nothing between the
descriptor bytes at uvc_driver.c:254, :255 and :382 and this line
validates any of the three. A zero then goes through uvc_video.c:214
into stream->ctrl, sizes vb2 at uvc_queue.c:90, and trips
WARN_ON(!plane_sizes[i]) in vb2_core_reqbufs() at
videobuf2-core.c:951. That is pre-existing and unchanged by your patch,
so it is not yours to fix here. I am happy to send a follow-up if the
maintainers want it as a separate change.
One caveat on my side: all of the above comes from reading the tree at
v7.2, not from running it. I did not test on hardware or a UVC gadget,
and I did not build your patch.
Natasha
next prev parent reply other threads:[~2026-08-18 6:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 10:14 [PATCH] " Noam Ben Shimon
2026-08-10 14:12 ` Ricardo Ribalda
2026-08-12 10:32 ` [PATCH v2] " Noam Ben Shimon
2026-08-18 6:45 ` Natasha Klaus [this message]
2026-08-18 6:54 ` Ricardo Ribalda
2026-08-18 6:57 ` Ricardo Ribalda
2026-08-20 9:53 ` Noam Ben
2026-08-18 7:59 ` [PATCH] media: uvcvideo: Skip frame descriptors with a zero computed size Natasha Klaus
2026-08-18 8:31 ` Ricardo Ribalda
2026-08-18 9:40 ` Natasha Klaus
2026-08-18 9:53 ` Natasha Klaus
2026-08-18 10:18 ` Ricardo Ribalda
2026-08-20 9:43 ` Noam Ben
2026-08-18 10:32 ` Natasha Klaus
2026-08-18 10:40 ` Ricardo Ribalda
2026-08-18 8:28 ` [PATCH] media: uvcvideo: Fix integer overflow in frame buffer size calculation David Laight
2026-08-20 9:13 ` Natasha Klaus
2026-08-20 10:31 ` David Laight
2026-08-20 10:01 ` Noam Ben
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=20260818064511.104024-1-natalie.klaus@runtimeverification.com \
--to=natalie.klaus@runtimeverification.com \
--cc=hansg@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=noambs2999@gmail.com \
--cc=ribalda@chromium.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®