Re: [PATCH 1/3] media: uvcvideo: Reject short metadata

From: Ricardo Ribalda

Date: Mon Nov 16 2026 - 08:23:55 EST


Hi Laurent


On Mon, 16 Nov 2026 at 14:08, Laurent Pinchart
<laurent.pinchart@xxxxxxxxxxxxxxxx> wrote:
>
> On Mon, Nov 16, 2026 at 11:56:37AM +0000, Ricardo Ribalda wrote:
> > The UVC header has two bits saying whether the packet contains the
> > optional PTS or SCR fields.
> >
> > If the header says that those fields are there, but the header is not
> > big enough to hold them, there is something wrong going on and we could
> > read out of bounds.
>
> There are multiple checks scattered through the code for this already,
> some of them causing the whole data packet to be dropped, others just
> short-circuiting operations such as clock and stats updates. Did you ned
> see those ? It's getting too messy.

Yes I saw them :P.

I can move the tests to uvc_video_decode_start(). The question is what
we should do for non compliant cameras.

I would love to just drop the packet altogether (with a non compliance
warning), and if someone complains... we can add a quirk or some
heuristics.

Will send a v2


>
> > Mark the metadata as invalid and move on.
> >
> > Reported-by: Sinan Turunc <enscrpt@xxxxx>
> > Closes: https://lore.kernel.org/linux-media/20261115121701.189-1-enscrpt@xxxxx/
> > Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
> > ---
> > drivers/media/usb/uvc/uvc_video.c | 8 ++++++++
> > drivers/media/usb/uvc/uvcvideo.h | 1 +
> > 2 files changed, 9 insertions(+)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > index a92a986ab714..9cc5d83acbc2 100644
> > --- a/drivers/media/usb/uvc/uvc_video.c
> > +++ b/drivers/media/usb/uvc/uvc_video.c
> > @@ -1487,6 +1487,14 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> > if (has_scr)
> > len_std += 6;
> >
> > + if (length < len_std) {
> > + uvc_warn_once(stream->dev, UVC_WARN_META_SHORT,
> > + "UVC non compliance: payload header length %u is shorter than expected %zu (flags 0x%02x).\n",
> > + length, len_std, mem[1]);
> > + meta_buf->error = 1;
> > + return;
> > + }
> > +
> > if (stream->meta.format == V4L2_META_FMT_UVC)
> > length = len_std;
> >
> > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> > index af8cef94ffff..59e23e55bc2e 100644
> > --- a/drivers/media/usb/uvc/uvcvideo.h
> > +++ b/drivers/media/usb/uvc/uvcvideo.h
> > @@ -661,6 +661,7 @@ static inline struct uvc_fh *to_uvc_fh(struct file *filp)
> > #define UVC_WARN_PROBE_DEF 1
> > #define UVC_WARN_XU_GET_RES 2
> > #define UVC_WARN_QUERY_CTRL 3
> > +#define UVC_WARN_META_SHORT 4
> >
> > extern unsigned int uvc_clock_param;
> > extern unsigned int uvc_no_drop_param;
>
> --
> Regards,
>
> Laurent Pinchart



--
Ricardo Ribalda