On Tue Jun 10 21:41:07 2025 +0900, Youngjun Lee wrote:
> 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 <[email protected]>
> Reviewed-by: Laurent Pinchart <[email protected]>
> Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver")
> Cc: [email protected]
> Reviewed-by: Ricardo Ribalda <[email protected]>
> Link: https://lore.kernel.org/r/[email protected]
> Signed-off-by: Laurent Pinchart <[email protected]>
> Signed-off-by: Hans Verkuil <[email protected]>

Patch committed.

Thanks,
Hans Verkuil

 drivers/media/usb/uvc/uvc_driver.c | 3 +++
 1 file changed, 3 insertions(+)

---

diff --git a/drivers/media/usb/uvc/uvc_driver.c 
b/drivers/media/usb/uvc/uvc_driver.c
index 916c2d13e268..62eb45435d8b 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -344,6 +344,9 @@ static int uvc_parse_format(struct uvc_device *dev,
        u8 ftype;
        int ret;
 
+       if (buflen < 4)
+               return -EINVAL;
+
        format->type = buffer[2];
        format->index = buffer[3];
        format->frames = frames;

Reply via email to