[PATCH 4.9 081/102] media: usbtv: prevent double free in error case

From: Greg Kroah-Hartman
Date: Fri Apr 06 2018 - 09:36:06 EST

4.9-stable review patch. If anyone has any objections, please let me know.


From: Oliver Neukum <oneukum@xxxxxxxx>

commit 50e7044535537b2a54c7ab798cd34c7f6d900bd2 upstream.

Quoting the original report:

It looks like there is a double-free vulnerability in Linux usbtv driver
on an error path of usbtv_probe function. When audio registration fails,
usbtv_video_free function ends up freeing usbtv data structure, which
gets freed the second time under usbtv_video_fail label.


usbtv_video_free(usbtv); =>


=> v4l2_device_put

=> kref_put

=> v4l2_device_release

=> usbtv_release (CALLBACK)

=> kfree(usbtv) (1st time)


usb_set_intfdata(intf, NULL);


kfree(usbtv); (2nd time)

So, as we have refcounting, use it

Reported-by: Yavuz, Tuba <tuba@xxxxxxxxxxx>
Signed-off-by: Oliver Neukum <oneukum@xxxxxxxx>
CC: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hans Verkuil <hans.verkuil@xxxxxxxxx>
Signed-off-by: Mauro Carvalho Chehab <mchehab@xxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

drivers/media/usb/usbtv/usbtv-core.c | 2 ++
1 file changed, 2 insertions(+)

--- a/drivers/media/usb/usbtv/usbtv-core.c
+++ b/drivers/media/usb/usbtv/usbtv-core.c
@@ -109,6 +109,8 @@ static int usbtv_probe(struct usb_interf
return 0;

+ /* we must not free at this point */
+ usb_get_dev(usbtv->udev);