mirror of
https://github.com/torvalds/linux.git
synced 2024-12-02 09:01:34 +00:00
[media] media: vb2: Take queue or device lock in mmap-related vb2 ioctl handlers
The vb2_fop_mmap() and vb2_fop_get_unmapped_area() functions are plug-in implementation of the mmap() and get_unmapped_area() file operations that calls vb2_mmap() and vb2_get_unmapped_area() on the queue associated with the video device. Neither the vb2_fop_mmap/vb2_fop_get_unmapped_area nor the v4l2_mmap/vb2_get_unmapped_area functions in the V4L2 core take any lock, leading to race conditions between mmap/get_unmapped_area and other buffer-related ioctls such as VIDIOC_REQBUFS. Fix it by taking the queue or device lock around the vb2_mmap() and vb2_get_unmapped_area() calls. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
This commit is contained in:
parent
5548a38250
commit
8a90f1a61c
@ -2578,8 +2578,15 @@ EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
|
||||
int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma)
|
||||
{
|
||||
struct video_device *vdev = video_devdata(file);
|
||||
struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
|
||||
int err;
|
||||
|
||||
return vb2_mmap(vdev->queue, vma);
|
||||
if (lock && mutex_lock_interruptible(lock))
|
||||
return -ERESTARTSYS;
|
||||
err = vb2_mmap(vdev->queue, vma);
|
||||
if (lock)
|
||||
mutex_unlock(lock);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vb2_fop_mmap);
|
||||
|
||||
@ -2685,8 +2692,15 @@ unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
|
||||
unsigned long len, unsigned long pgoff, unsigned long flags)
|
||||
{
|
||||
struct video_device *vdev = video_devdata(file);
|
||||
struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
|
||||
int ret;
|
||||
|
||||
return vb2_get_unmapped_area(vdev->queue, addr, len, pgoff, flags);
|
||||
if (lock && mutex_lock_interruptible(lock))
|
||||
return -ERESTARTSYS;
|
||||
ret = vb2_get_unmapped_area(vdev->queue, addr, len, pgoff, flags);
|
||||
if (lock)
|
||||
mutex_unlock(lock);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vb2_fop_get_unmapped_area);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user