[PATCH v2 2/6] media: uvcvideo: Fix unaligned and OOB access in uvc_video_decode_meta()

From: Ricardo Ribalda

Date: Mon Nov 16 2026 - 12:52:37 EST


meta->buf and scr point to packed metadata and USB packet memory that do
not need to be aligned to anything, and store little-endian values.

Also, scr + 4 is a 16-bit field, so reading it as a u32 could
potentially read 2 bytes beyond the packet.

Last but not least, the old code printed wrong values on big-endian
arches.

Fix this.

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 | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index e801874e272e..8bae91af03ba 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1542,9 +1542,9 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
"%s(): t-sys %lluns, SOF %u, len %u, flags 0x%x, PTS %u, STC %u frame SOF %u\n",
__func__, ktime_to_ns(time), meta->sof, meta->length,
meta->flags,
- has_pts ? *(u32 *)meta->buf : 0,
- has_scr ? *(u32 *)scr : 0,
- has_scr ? *(u32 *)(scr + 4) & 0x7ff : 0);
+ has_pts ? get_unaligned_le32(meta->buf) : 0,
+ has_scr ? get_unaligned_le32(scr) : 0,
+ has_scr ? get_unaligned_le16(scr + 4) & 0x7ff : 0);
}

/* ------------------------------------------------------------------------

--
2.56.0.679.gc527c65306-goog