[PATCH v2 0/6] media: uvcvideo: Improve checks for payload header size
From: Ricardo Ribalda
Date: Mon Nov 16 2026 - 12:52:23 EST
Payload header length checks against the PTS/SCR flags are scattered
through the driver, with different behaviour in each place, and
uvc_video_decode_meta() lacked the check altogether, which could lead to
out of bounds reads.
Validate the header length once in uvc_video_decode_start(), dropping
non-compliant packets with a warning, and remove the now redundant
checks.
While doing that, I also spotted an unaligned and OOB access in a debug
message, and two places in stats and clock decode that used the minimum
header size instead of bHeaderLength when checking if a packet contains
payload data. Fix those and factor out header timestamp parsing into a
new uvc_video_parse_pts_stc_sof() helper.
I have used an LLM to review the code and commit messages.
This work was triggered by:
https://lore.kernel.org/linux-media/20261115121701.189-1-enscrpt@xxxxx
Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
---
Changes in v2:
- Validate the header length once in uvc_video_decode_start() and drop
non-compliant packets, instead of adding more scattered checks
(Laurent).
- Drop "Check header length in uvc_video_clock_decode()", now covered by
patch 1.
- New patches fixing stats and clock decode to use bHeaderLength
(data[0]) instead of the minimum header size when checking for payload
data.
- New patch removing the now redundant checks in clock and stats decode.
- New patch adding uvc_video_parse_pts_stc_sof() to factor out header
timestamp parsing (inspired by Laurent's review).
- Link to v1: https://lore.kernel.org/r/20261116-uvc-shortmeta-v1-0-487cfe42fa89@xxxxxxxxxxxx
---
Ricardo Ribalda (6):
media: uvcvideo: Reject payloads with a short header
media: uvcvideo: Fix unaligned and OOB access in uvc_video_decode_meta()
media: uvcvideo: Use bHeaderLength for payload size in stats
media: uvcvideo: Use bHeaderLength to detect empty packets in clock decode
media: uvcvideo: Remove redundant payload header length checks
media: uvcvideo: Add uvc_video_parse_pts_stc_sof()
drivers/media/usb/uvc/uvc_video.c | 173 +++++++++++++++++---------------------
drivers/media/usb/uvc/uvcvideo.h | 4 +-
2 files changed, 78 insertions(+), 99 deletions(-)
---
base-commit: 48fe5a7834cc10081887d7bcd9ff0a4cadc3fa8c
change-id: 20261116-uvc-shortmeta-75ccb6707d9d
Best regards,
--
Ricardo Ribalda <ribalda@xxxxxxxxxxxx>