Skip to content

Commit 4e11637

Browse files
Muhammad Bilalgregkh
authored andcommitted
usb: gadget: uvc: clamp SEND_RESPONSE length to the response buffer
commit b70dc75 upstream. uvc_send_response() builds the UVC control response from a user-supplied struct uvc_request_data: req->length = min_t(unsigned int, uvc->event_length, data->length); ... memcpy(req->buf, data->data, req->length); req->length is clamped to uvc->event_length, which is taken from the host control request wLength (up to UVC_MAX_REQUEST_SIZE, 64), and to data->length, which comes from the UVCIOC_SEND_RESPONSE ioctl and is only checked for being negative. The source buffer data->data is only 60 bytes, so a response with uvc->event_length and data->length both greater than 60 makes memcpy() read past the end of data->data. Clamp req->length to sizeof(data->data) as well. Fixes: a5eaaa1 ("usb: gadget: uvc: use capped length value") Cc: stable <stable@kernel.org> Signed-off-by: Muhammad Bilal <meatuni001@gmail.com> Link: https://patch.msgid.link/20260629195004.148405-1-meatuni001@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1a1d715 commit 4e11637

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/usb/gadget/function/uvc_v4l2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
191191
return usb_ep_set_halt(cdev->gadget->ep0);
192192

193193
req->length = min_t(unsigned int, uvc->event_length, data->length);
194+
if (req->length > sizeof(data->data))
195+
req->length = sizeof(data->data);
194196
req->zero = data->length < uvc->event_length;
195197

196198
memcpy(req->buf, data->data, req->length);

0 commit comments

Comments
 (0)