media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()

The buffer length check before calling uvc_parse_format() only ensured
that the buffer has at least 3 bytes (buflen > 2), buf the function
accesses buffer[3], requiring at least 4 bytes.

This can lead to an out-of-bounds read if the buffer has exactly 3 bytes.

Fix it by checking that the buffer has at least 4 bytes in
uvc_parse_format().

Signed-off-by: Youngjun Lee <yjjuny.lee@samsung.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Fixes: c0efd23292 ("V4L/DVB (8145a): USB Video Class driver")
Cc: stable@vger.kernel.org
Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
Link: https://lore.kernel.org/r/20250610124107.37360-1-yjjuny.lee@samsung.com
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
This commit is contained in:
Youngjun Lee 2025-06-10 21:41:07 +09:00 committed by Hans Verkuil
parent 53b0b80e52
commit 782b6a7186
1 changed files with 3 additions and 0 deletions

View File

@ -344,6 +344,9 @@ static int uvc_parse_format(struct uvc_device *dev,
u8 ftype; u8 ftype;
int ret; int ret;
if (buflen < 4)
return -EINVAL;
format->type = buffer[2]; format->type = buffer[2];
format->index = buffer[3]; format->index = buffer[3];
format->frames = frames; format->frames = frames;