Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] media: uvcvideo: Reject metadata packets shorter than their header
@ 2026-11-15 12:17 Sinan Turunc
  2026-11-16  2:13 ` Laurent Pinchart
  0 siblings, 1 reply; 2+ messages in thread
From: Sinan Turunc @ 2026-11-15 12:17 UTC (permalink / raw)
  To: Laurent Pinchart, Hans de Goede
  Cc: mchehab, linux-media, linux-kernel, stable

uvc_video_decode_meta() derives the length of a UVC payload header
from the PTS and SCR flag bits in the packet, not from the packet
length, and with V4L2_META_FMT_UVC it copies that many bytes with
memcpy(meta->buf, &mem[2], length - 2). Nothing compares the derived
length with the packet length, so a packet shorter than the header it
claims is read past its end, and the bytes beyond it - whatever the
URB buffer held there before - are copied into the metadata buffer
that userspace reads.

An emulated UVC camera that sends an 8-byte isochronous packet with a
3-byte header and both the PTS and SCR bits set made the copy take 10
bytes from mem[2]: the last four came from past the packet, and in one
run those four were the tail of the previous packet still in the URB
buffer (03 0c, a UVC header) rather than zeros. With this patch the
same device delivers no metadata blocks at all, and the video stream
is unchanged: 25905 buffers, 5958150 bytes over a 30-second window.

The check is placed after the derived length is final and before the
format override, and treats such a packet the way the function already
treats a 2-byte one: it returns.

Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
Cc: stable@vger.kernel.org
Signed-off-by: Sinan Turunc <enscrpt@pm.me>
---
 drivers/media/usb/uvc/uvc_video.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index fc3536a4399..25c3b8dc891 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1487,6 +1487,10 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
 	if (has_scr)
 		len_std += 6;
 
+	/* A packet shorter than the header it declares is malformed. */
+	if (length < len_std)
+		return;
+
 	if (stream->meta.format == V4L2_META_FMT_UVC)
 		length = len_std;
 
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: uvcvideo: Reject metadata packets shorter than their header
  2026-11-15 12:17 [PATCH] media: uvcvideo: Reject metadata packets shorter than their header Sinan Turunc
@ 2026-11-16  2:13 ` Laurent Pinchart
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2026-11-16  2:13 UTC (permalink / raw)
  To: Sinan Turunc; +Cc: Hans de Goede, mchehab, linux-media, linux-kernel, stable

Hello,

This is an automated reply.

You have sent a patch or bug report that appears to have been generated
by an LLM. The commit message, code and/or problem description show
little to no real understanding of the issue and changes being proposed.

Such patches or reports require a large amount of work to handle. They
rely on maintainers to propose - and often even implement - a proper
design. The probability that the author will learn from the experience
to improve their future contributions is close to zero.

As a result, to make good use of maintainer time and keep the kernel
development process sustainable, your contribution has been rejected.

If you believe the change you proposed is important, take time to study
the problem, learn, and develop a solution without AI assistance.
Answering this e-mail or generating a new version of a patch by feeding
this reply to an LLM will only result in your e-mails being ignored.

Please note that if your patch attempted to address an important
problem, maintainers or other contributors can submit and merge a
similar or entirely different fix without crediting you.

Your contributions to the Linux kernel will be welcome if you genuinely
desire to invest your time and learn.

Thank you,

Laurent's mail bot

On Sun, 15 Nov 2026 12:17:18 +0000, Sinan Turunc <enscrpt@pm.me> wrote:
> uvc_video_decode_meta() derives the length of a UVC payload header
> from the PTS and SCR flag bits in the packet, not from the packet
> length, and with V4L2_META_FMT_UVC it copies that many bytes with
> memcpy(meta->buf, &mem[2], length - 2). Nothing compares the derived
> length with the packet length, so a packet shorter than the header it
> claims is read past its end, and the bytes beyond it - whatever the
> URB buffer held there before - are copied into the metadata buffer
> that userspace reads.
> 
> An emulated UVC camera that sends an 8-byte isochronous packet with a
> 3-byte header and both the PTS and SCR bits set made the copy take 10
> bytes from mem[2]: the last four came from past the packet, and in one
> run those four were the tail of the previous packet still in the URB
> buffer (03 0c, a UVC header) rather than zeros. With this patch the
> same device delivers no metadata blocks at all, and the video stream
> is unchanged: 25905 buffers, 5958150 bytes over a 30-second window.
> 
> The check is placed after the derived length is final and before the
> format override, and treats such a packet the way the function already
> treats a 2-byte one: it returns.
> 
> Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sinan Turunc <enscrpt@pm.me>
> ---
>  drivers/media/usb/uvc/uvc_video.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index fc3536a4399..25c3b8dc891 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1487,6 +1487,10 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
>  	if (has_scr)
>  		len_std += 6;
>  
> +	/* A packet shorter than the header it declares is malformed. */
> +	if (length < len_std)
> +		return;
> +
>  	if (stream->meta.format == V4L2_META_FMT_UVC)
>  		length = len_std;
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16  2:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 12:17 [PATCH] media: uvcvideo: Reject metadata packets shorter than their header Sinan Turunc
2026-11-16  2:13 ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox