From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Natasha Klaus <natalie.klaus@runtimeverification.com>
Cc: hansg@kernel.org, mchehab@kernel.org, ribalda@chromium.org,
noambs2999@gmail.com, david.laight.linux@gmail.com,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v3 1/3] media: uvcvideo: Let uvc_parse_frame() report a skipped frame
Date: Mon, 28 Sep 2026 23:50:37 +0300 [thread overview]
Message-ID: <20260928205037.GL4406@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20260820111556.232652-2-natalie.klaus@runtimeverification.com>
On Thu, Aug 20, 2026 at 02:15:54PM +0300, Natasha Klaus wrote:
> uvc_parse_frame() returns the descriptor length on success and a
> negative error code on failure, and uvc_parse_format() treats every
> negative value as fatal for the whole streaming interface. There is no
> way for the parser to say "this frame descriptor is unusable, but the
> rest of the format is fine".
On what device have you seen this occurring ? How did you test this
patch ?
> Change the return convention so it can. Return 0 on success and let the
> caller advance by buffer[0], which is the value the function returned
> anyway. Report a truncated descriptor with -ENODATA, which stays fatal,
> and leave every other negative value to mean "skip this frame descriptor
> and carry on with the next one".
>
> -ENODATA is currently the only error the function can return, so the
> skip path is unreachable until later patches add checks that use it. The
> one behavioural change is the truncated-descriptor diagnostic, which
> moves from uvc_dbg() to dev_warn() so a malformed descriptor is reported
> without the DESCR debug flag. That leaves the local alts variable
> unused, and the kernel builds -Wunused-variable as an error, so it goes
> too.
>
> Suggested-by: Ricardo Ribalda <ribalda@chromium.org>
> Link: https://lore.kernel.org/linux-media/CANiDSCue8yyiGubzbAybRqSUTTFuB=-Y2TZy6yvOx32SpAASWg@mail.gmail.com/
> Cc: stable@vger.kernel.org
> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
> Tested-by: Noam Ben Shimon <noambs2999@gmail.com>
> Signed-off-by: Natasha Klaus <natalie.klaus@runtimeverification.com>
> ---
> The Cc: stable line is present without a Fixes: tag because this patch is
> a prerequisite for 2/3 rather than a fix in its own right. Stable needs
> both or neither: backported alone, 2/3's -EINVAL would revert to meaning
> "discard the whole streaming interface".
>
> The caller checks -ENODATA before counting the frame, per Ricardo's review.
> Behaviour is unchanged either way, since -ENODATA is non-zero, but the fatal
> case reads better first.
>
> drivers/media/usb/uvc/uvc_driver.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
> index e289cc71ba98..b94fe5366e55 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -230,7 +230,6 @@ static int uvc_parse_frame(struct uvc_device *dev,
> u32 **intervals, u8 ftype, int width_multiplier,
> const unsigned char *buffer, int buflen)
> {
> - struct usb_host_interface *alts = streaming->intf->cur_altsetting;
> unsigned int maxIntervalIndex;
> unsigned int interval;
> unsigned int i, n;
> @@ -243,10 +242,10 @@ static int uvc_parse_frame(struct uvc_device *dev,
> n = n ? n : 3;
>
> if (buflen < 26 + 4 * n) {
> - uvc_dbg(dev, DESCR,
> - "device %d videostreaming interface %d FRAME error\n",
> - dev->udev->devnum, alts->desc.bInterfaceNumber);
> - return -EINVAL;
> + dev_warn(&streaming->intf->dev,
> + "UVC non compliance: FRAME descriptor is %d bytes, expected at least %u.\n",
> + buflen, 26 + 4 * n);
> + return -ENODATA;
> }
>
> frame->bFrameIndex = buffer[3];
> @@ -329,7 +328,7 @@ static int uvc_parse_frame(struct uvc_device *dev,
>
> *intervals += n;
>
> - return buffer[0];
> + return 0;
> }
>
> static int uvc_parse_format(struct uvc_device *dev,
> @@ -492,11 +491,12 @@ static int uvc_parse_format(struct uvc_device *dev,
> ret = uvc_parse_frame(dev, streaming, format, frame,
> intervals, ftype, width_multiplier,
> buffer, buflen);
> - if (ret < 0)
> + if (ret == -ENODATA)
> return ret;
> - format->nframes++;
> - buflen -= ret;
> - buffer += ret;
> + if (!ret)
> + format->nframes++;
> + buflen -= buffer[0];
> + buffer += buffer[0];
> }
> }
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-09-28 20:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 11:15 [PATCH v3 0/3] media: uvcvideo: harden the frame buffer size computation Natasha Klaus
2026-08-20 11:15 ` [PATCH v3 1/3] media: uvcvideo: Let uvc_parse_frame() report a skipped frame Natasha Klaus
2026-09-28 20:50 ` Laurent Pinchart [this message]
2026-08-20 11:15 ` [PATCH v3 2/3] media: uvcvideo: Fix integer overflow in frame buffer size calculation Natasha Klaus
2026-09-28 20:53 ` Laurent Pinchart
2026-08-20 11:15 ` [PATCH v3 3/3] media: uvcvideo: Skip frame descriptors with a zero computed size Natasha Klaus
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=20260928205037.GL4406@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=david.laight.linux@gmail.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=natalie.klaus@runtimeverification.com \
--cc=noambs2999@gmail.com \
--cc=ribalda@chromium.org \
--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®