From: Hans de Goede <hansg@kernel.org>
To: Ricardo Ribalda <ribalda@chromium.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] media: uvcvideo: Do not read beyond the uvc_status_control memory
Date: Mon, 30 Nov 2026 16:44:40 +0100 [thread overview]
Message-ID: <ef26ed45-5d23-42d6-a23a-dcec6216d68b@kernel.org> (raw)
In-Reply-To: <20261002-uvc-status-11-v2-2-a98a135df0eb@chromium.org>
Hi,
On 2-Oct-26 13:21, Ricardo Ribalda wrote:
> When we receive an event from the camera we only receive up to
> wMaxPacketSize bytes. If a v4l2 control is mapped into a UVC control
> beyond those bytes, right now the code is blindly reading them.
>
> Add a check in the event handler to ignore controls that are outside the
> data provided by the camera.
>
> Note that this patch now dynamically allocates the size for the status
> based on wMaxPacketSize instead of blindly use 16 bytes.
>
> Cc: stable@vger.kernel.org
> Closes: https://sashiko.dev/#/patchset/F0F008459FFA835D%2B20260813074632.2021311-1-raoxu%40uniontech.com
> Fixes: e5225c820c05 ("media: uvcvideo: Send a control event when a Control Change interrupt arrives")
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Regards,
Hans
> ---
> drivers/media/usb/uvc/uvc_ctrl.c | 12 +++++++++---
> drivers/media/usb/uvc/uvc_driver.c | 2 +-
> drivers/media/usb/uvc/uvc_status.c | 18 +++++++++++++-----
> drivers/media/usb/uvc/uvcvideo.h | 9 ++++++---
> 4 files changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index 6224ecf28ec6..e61235e83e80 100644
> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
> @@ -2142,7 +2142,8 @@ static int uvc_ctrl_clear_handle(struct uvc_control *ctrl)
> }
>
> void uvc_ctrl_status_event(struct uvc_video_chain *chain,
> - struct uvc_control *ctrl, const u8 *data)
> + struct uvc_control *ctrl, const u8 *data,
> + size_t size)
> {
> struct uvc_control_mapping *mapping;
> struct uvc_fh *handle;
> @@ -2162,6 +2163,9 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain,
>
> if (uvc_ctrl_mapping_is_compound(mapping))
> value = 0;
> + else if (DIV_ROUND_UP(mapping->offset + mapping->size, 8) >
> + size)
> + continue;
> else
> value = uvc_mapping_get_s32(mapping, UVC_GET_CUR, data);
>
> @@ -2191,7 +2195,7 @@ static void uvc_ctrl_status_event_work(struct work_struct *work)
> struct uvc_ctrl_work *w = &dev->async_ctrl;
> int ret;
>
> - uvc_ctrl_status_event(w->chain, w->ctrl, w->data);
> + uvc_ctrl_status_event(w->chain, w->ctrl, w->data, w->size);
>
> /* The barrier is needed to synchronize with uvc_status_stop(). */
> if (smp_load_acquire(&dev->flush_status))
> @@ -2206,7 +2210,8 @@ static void uvc_ctrl_status_event_work(struct work_struct *work)
> }
>
> bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain,
> - struct uvc_control *ctrl, const u8 *data)
> + struct uvc_control *ctrl, const u8 *data,
> + size_t size)
> {
> struct uvc_device *dev = chain->dev;
> struct uvc_ctrl_work *w = &dev->async_ctrl;
> @@ -2218,6 +2223,7 @@ bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain,
> w->urb = urb;
> w->chain = chain;
> w->ctrl = ctrl;
> + w->size = size;
>
> schedule_work(&w->work);
>
> diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
> index 468d46dfb9e7..b57825fadea1 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -1305,7 +1305,7 @@ static void uvc_gpio_event(struct uvc_device *dev)
>
> /* GPIO entities are always on the first chain. */
> chain = list_first_entry(&dev->chains, struct uvc_video_chain, list);
> - uvc_ctrl_status_event(chain, unit->controls, &new_val);
> + uvc_ctrl_status_event(chain, unit->controls, &new_val, sizeof(new_val));
> }
>
> static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
> diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
> index 97c939206302..a88fa57513fb 100644
> --- a/drivers/media/usb/uvc/uvc_status.c
> +++ b/drivers/media/usb/uvc/uvc_status.c
> @@ -169,6 +169,7 @@ static bool uvc_event_control(struct urb *urb,
> struct uvc_device *dev = urb->context;
> struct uvc_video_chain *chain;
> struct uvc_control *ctrl;
> + size_t ctrl_len;
>
> if (len < 6 || status->bEvent != 0 ||
> status->control.bAttribute >= ARRAY_SIZE(attrs)) {
> @@ -187,8 +188,10 @@ static bool uvc_event_control(struct urb *urb,
>
> switch (status->control.bAttribute) {
> case UVC_CTRL_VALUE_CHANGE:
> + ctrl_len = len - offsetof(struct uvc_status, control.bValue);
> return uvc_ctrl_status_event_async(urb, chain, ctrl,
> - status->control.bValue);
> + status->control.bValue,
> + ctrl_len);
>
> case UVC_CTRL_INFO_CHANGE:
> case UVC_CTRL_FAILURE_CHANGE:
> @@ -257,13 +260,18 @@ int uvc_status_init(struct uvc_device *dev)
> struct usb_host_endpoint *ep = dev->int_ep;
> unsigned int pipe;
> int interval;
> + size_t size;
>
> mutex_init(&dev->status_lock);
>
> if (ep == NULL)
> return 0;
>
> - dev->status = kzalloc_obj(*dev->status);
> + size = usb_endpoint_maxp(&ep->desc);
> + if (!size)
> + return -EINVAL;
> +
> + dev->status = kzalloc(size, GFP_KERNEL);
> if (!dev->status)
> return -ENOMEM;
>
> @@ -286,7 +294,7 @@ int uvc_status_init(struct uvc_device *dev)
> interval = fls(interval) - 1;
>
> usb_fill_int_urb(dev->int_urb, dev->udev, pipe,
> - dev->status, sizeof(*dev->status), uvc_status_complete,
> + dev->status, size, uvc_status_complete,
> dev, interval);
>
> uvc_input_init(dev);
> @@ -360,7 +368,7 @@ static void uvc_status_stop(struct uvc_device *dev)
> * process it synchronously.
> */
> if (cancel_work_sync(&w->work))
> - uvc_ctrl_status_event(w->chain, w->ctrl, w->data);
> + uvc_ctrl_status_event(w->chain, w->ctrl, w->data, w->size);
>
> /* Kill the urb. */
> usb_kill_urb(dev->int_urb);
> @@ -372,7 +380,7 @@ static void uvc_status_stop(struct uvc_device *dev)
> * uvc_status_start() call.
> */
> if (cancel_work_sync(&w->work))
> - uvc_ctrl_status_event(w->chain, w->ctrl, w->data);
> + uvc_ctrl_status_event(w->chain, w->ctrl, w->data, w->size);
> }
>
> int uvc_status_resume(struct uvc_device *dev)
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 69ee3d0c971d..788cee0c409d 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -567,7 +567,7 @@ struct uvc_status_streaming {
> struct uvc_status_control {
> u8 bSelector;
> u8 bAttribute;
> - u8 bValue[11];
> + u8 bValue[];
> } __packed;
>
> struct uvc_status {
> @@ -629,6 +629,7 @@ struct uvc_device {
> struct uvc_video_chain *chain;
> struct uvc_control *ctrl;
> const void *data;
> + size_t size;
> } async_ctrl;
>
> struct uvc_entity *gpio_unit;
> @@ -771,9 +772,11 @@ int uvc_ctrl_init_device(struct uvc_device *dev);
> void uvc_ctrl_cleanup_device(struct uvc_device *dev);
> int uvc_ctrl_restore_values(struct uvc_device *dev);
> bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain,
> - struct uvc_control *ctrl, const u8 *data);
> + struct uvc_control *ctrl, const u8 *data,
> + size_t size);
> void uvc_ctrl_status_event(struct uvc_video_chain *chain,
> - struct uvc_control *ctrl, const u8 *data);
> + struct uvc_control *ctrl, const u8 *data,
> + size_t size);
>
> int uvc_ctrl_begin(struct uvc_video_chain *chain);
> int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
>
next prev parent reply other threads:[~2026-11-30 15:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 11:21 [PATCH v2 0/2] media: uvcvideo: Do not read beyond the uvc_status urb Ricardo Ribalda
2026-10-02 11:21 ` [PATCH v2 1/2] media: uvcvideo: Introduce scattered field for uvc_control_mapping Ricardo Ribalda
2026-11-30 15:41 ` Hans de Goede
2026-10-02 11:21 ` [PATCH v2 2/2] media: uvcvideo: Do not read beyond the uvc_status_control memory Ricardo Ribalda
2026-11-30 15:44 ` Hans de Goede [this message]
2026-11-30 15:50 ` [PATCH v2 0/2] media: uvcvideo: Do not read beyond the uvc_status urb Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ef26ed45-5d23-42d6-a23a-dcec6216d68b@kernel.org \
--to=hansg@kernel.org \
--cc=guennadi.liakhovetski@intel.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab+samsung@kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox