diff mbox series

media: uvcvideo: Fix double free in error path

Message ID 20241107235130.31372-1-laurent.pinchart@ideasonboard.com
State New
Headers show
Series media: uvcvideo: Fix double free in error path | expand

Commit Message

Laurent Pinchart Nov. 7, 2024, 11:51 p.m. UTC
If the uvc_status_init() function fails to allocate the int_urb, it will
free the dev->status pointer but doesn't reset the pointer to NULL. This
results in the kfree() call in uvc_status_cleanup() trying to
double-free the memory. Fix it by resetting the dev->status pointer to
NULL after freeing it.

Fixes: a31a4055473b ("V4L/DVB:usbvideo:don't use part of buffer for USB transfer #4")
Cc: stable@vger.kernel.org
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/usb/uvc/uvc_status.c | 1 +
 1 file changed, 1 insertion(+)


base-commit: ed61c59139509f76d3592683c90dc3fdc6e23cd6

Comments

Ricardo Ribalda Nov. 8, 2024, 7:23 a.m. UTC | #1
On Fri, 8 Nov 2024 at 00:51, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> If the uvc_status_init() function fails to allocate the int_urb, it will
> free the dev->status pointer but doesn't reset the pointer to NULL. This
> results in the kfree() call in uvc_status_cleanup() trying to
> double-free the memory. Fix it by resetting the dev->status pointer to
> NULL after freeing it.
>
> Fixes: a31a4055473b ("V4L/DVB:usbvideo:don't use part of buffer for USB transfer #4")
> Cc: stable@vger.kernel.org
Reviewed by: Ricardo Ribalda <ribalda@chromium.org>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/usb/uvc/uvc_status.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
> index 02c90acf6964..d269d163b579 100644
> --- a/drivers/media/usb/uvc/uvc_status.c
> +++ b/drivers/media/usb/uvc/uvc_status.c
> @@ -269,6 +269,7 @@ int uvc_status_init(struct uvc_device *dev)
>         dev->int_urb = usb_alloc_urb(0, GFP_KERNEL);
>         if (!dev->int_urb) {
>                 kfree(dev->status);
> +               dev->status = NULL;
>                 return -ENOMEM;
>         }
>
>
> base-commit: ed61c59139509f76d3592683c90dc3fdc6e23cd6
> --
> Regards,
>
> Laurent Pinchart
>
diff mbox series

Patch

diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
index 02c90acf6964..d269d163b579 100644
--- a/drivers/media/usb/uvc/uvc_status.c
+++ b/drivers/media/usb/uvc/uvc_status.c
@@ -269,6 +269,7 @@  int uvc_status_init(struct uvc_device *dev)
 	dev->int_urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!dev->int_urb) {
 		kfree(dev->status);
+		dev->status = NULL;
 		return -ENOMEM;
 	}