]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: video-i2c: avoid accessing released memory area when removing driver
authorAkinobu Mita <akinobu.mita@gmail.com>
Sat, 20 Oct 2018 14:26:23 +0000 (10:26 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 23 Nov 2018 09:33:36 +0000 (04:33 -0500)
The video device release() callback for video-i2c driver frees the whole
struct video_i2c_data.  If there is no user left for the video device
when video_unregister_device() is called, the release callback is executed.

However, in video_i2c_remove() some fields (v4l2_dev, lock, and queue_lock)
in struct video_i2c_data are still accessed after video_unregister_device()
is called.

This fixes the use after free by moving the code from video_i2c_remove()
to the release() callback.

Fixes: 5cebaac60974 ("media: video-i2c: add video-i2c driver")
Reviewed-by: Matt Ranostay <matt.ranostay@konsulko.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/i2c/video-i2c.c

index 4d49af86c15ee4a21b6f2e58d51dac4de6a6ddb9..ec0758dca2fcdcf1f01e228eb42f8acfb2d9d089 100644 (file)
@@ -510,7 +510,12 @@ static const struct v4l2_ioctl_ops video_i2c_ioctl_ops = {
 
 static void video_i2c_release(struct video_device *vdev)
 {
-       kfree(video_get_drvdata(vdev));
+       struct video_i2c_data *data = video_get_drvdata(vdev);
+
+       v4l2_device_unregister(&data->v4l2_dev);
+       mutex_destroy(&data->lock);
+       mutex_destroy(&data->queue_lock);
+       kfree(data);
 }
 
 static int video_i2c_probe(struct i2c_client *client,
@@ -608,10 +613,6 @@ static int video_i2c_remove(struct i2c_client *client)
        struct video_i2c_data *data = i2c_get_clientdata(client);
 
        video_unregister_device(&data->vdev);
-       v4l2_device_unregister(&data->v4l2_dev);
-
-       mutex_destroy(&data->lock);
-       mutex_destroy(&data->queue_lock);
 
        return 0;
 }