[media] drivers/media/media-device: fix double free bug in _unregister()
authorMax Kellermann <max.kellermann@gmail.com>
Tue, 9 Aug 2016 21:33:03 +0000 (18:33 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Fri, 18 Nov 2016 17:29:27 +0000 (15:29 -0200)
While removing all interfaces in media_device_unregister(), all
media_interface pointers are freed.  This is illegal and results in
double kfree() if any media_interface is still linked at this point;
maybe because a userspace process still has a file handle.  Once the
process closes the file handle, dvb_media_device_free() gets called,
which frees the dvb_device.intf_devnode again.

This patch removes the unnecessary kfree() call, and documents who's
responsible for really freeing it.

Signed-off-by: Max Kellermann <max.kellermann@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/media-device.c

index 2783531..219ab5f 100644 (file)
@@ -801,9 +801,13 @@ void media_device_unregister(struct media_device *mdev)
        /* Remove all interfaces from the media device */
        list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
                                 graph_obj.list) {
+               /*
+                * Unlink the interface, but don't free it here; the
+                * module which created it is responsible for freeing
+                * it
+                */
                __media_remove_intf_links(intf);
                media_gobj_destroy(&intf->graph_obj);
-               kfree(intf);
        }
 
        mutex_unlock(&mdev->graph_mutex);