media: ti-vpe: vip: avoid double free on video register failure
Subsystems (2)
PATCH 1/1 media: ti-vpe: vip: avoid double free on video register failure
alloc_stream() allocates a video_device with video_device_alloc() and releases it from the do_free_vfd error path if video_register_device() fails.
This can double free the video_device when __video_register_device() reaches device_register() and that call fails:
video_register_device()
-> __video_register_device()
-> device_register() fails
-> put_device(&vdev->dev)
-> v4l2_device_release()
-> vdev->release(vdev)
-> video_device_release(vdev) alloc_stream()
-> do_free_vfd
-> video_device_release(vfd)Use video_device_release_empty() while registering the device so that registration failure paths do not free vfd through vdev->release(). alloc_stream() then releases vfd exactly once from do_free_vfd. Restore video_device_release() after successful registration so the registered device keeps its normal lifetime handling.
This issue was found by a static analysis tool I am developing.
--- drivers/media/platform/ti/vpe/vip.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/platform/ti/vpe/vip.c +3 -0
@@ -3094,6 +3094,7 @@ static int alloc_stream(struct vip_port *port, int stream_id, int vfl_type) goto do_free_dropq; } *vfd = vip_videodev; + vfd->release = video_device_release_empty; vfd->v4l2_dev = &dev->v4l2_dev; vfd->queue = q;
@@ -3107,6 +3108,8 @@ static int alloc_stream(struct vip_port *port, int stream_id, int vfl_type) goto do_free_vfd; } + vfd->release = video_device_release; +v4l2_info (&dev->v4l2_dev,"device registered as %s\n" ,video_device_node_name (vfd));return 0 ;
Signature · 1 line
2.43.0