diff options
author | Al Viro <viro@ZenIV.linux.org.uk> | 2012-12-16 14:04:46 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-01-06 08:01:06 -0500 |
commit | 55ee64b30a38d688232e5eb2860467dddc493573 (patch) | |
tree | 5776c2b2e2db1a231ff6097e1c3c235af7703285 /drivers/media/platform/omap | |
parent | a0a030bdbe612b7d8a941fba672300f7fc21b275 (diff) |
[media] omap_vout: find_vma() needs ->mmap_sem held
Walking rbtree while it's modified is a Bad Idea(tm); besides,
the result of find_vma() can be freed just as it's getting returned
to caller. Fortunately, it's easy to fix - just take ->mmap_sem a bit
earlier (and don't bother with find_vma() at all if virtp >= PAGE_OFFSET -
in that case we don't even look at its result).
While we are at it, what prevents VIDIOC_PREPARE_BUF calling
v4l_prepare_buf() -> (e.g) vb2_ioctl_prepare_buf() -> vb2_prepare_buf() ->
__buf_prepare() -> __qbuf_userptr() -> vb2_vmalloc_get_userptr() -> find_vma(),
AFAICS without having taken ->mmap_sem anywhere in process? The code flow
is bloody convoluted and depends on a bunch of things done by initialization,
so I certainly might've missed something...
Cc: stable@vger.kernel.org [2.6.35]
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Archit Taneja <archit@ti.com>
Cc: Prabhakar Lad <prabhakar.lad@ti.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/platform/omap')
-rw-r--r-- | drivers/media/platform/omap/omap_vout.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c index dade3ceab092..96c4a17e4280 100644 --- a/drivers/media/platform/omap/omap_vout.c +++ b/drivers/media/platform/omap/omap_vout.c | |||
@@ -205,19 +205,21 @@ static u32 omap_vout_uservirt_to_phys(u32 virtp) | |||
205 | struct vm_area_struct *vma; | 205 | struct vm_area_struct *vma; |
206 | struct mm_struct *mm = current->mm; | 206 | struct mm_struct *mm = current->mm; |
207 | 207 | ||
208 | vma = find_vma(mm, virtp); | ||
209 | /* For kernel direct-mapped memory, take the easy way */ | 208 | /* For kernel direct-mapped memory, take the easy way */ |
210 | if (virtp >= PAGE_OFFSET) { | 209 | if (virtp >= PAGE_OFFSET) |
211 | physp = virt_to_phys((void *) virtp); | 210 | return virt_to_phys((void *) virtp); |
212 | } else if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) { | 211 | |
212 | down_read(¤t->mm->mmap_sem); | ||
213 | vma = find_vma(mm, virtp); | ||
214 | if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) { | ||
213 | /* this will catch, kernel-allocated, mmaped-to-usermode | 215 | /* this will catch, kernel-allocated, mmaped-to-usermode |
214 | addresses */ | 216 | addresses */ |
215 | physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start); | 217 | physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start); |
218 | up_read(¤t->mm->mmap_sem); | ||
216 | } else { | 219 | } else { |
217 | /* otherwise, use get_user_pages() for general userland pages */ | 220 | /* otherwise, use get_user_pages() for general userland pages */ |
218 | int res, nr_pages = 1; | 221 | int res, nr_pages = 1; |
219 | struct page *pages; | 222 | struct page *pages; |
220 | down_read(¤t->mm->mmap_sem); | ||
221 | 223 | ||
222 | res = get_user_pages(current, current->mm, virtp, nr_pages, 1, | 224 | res = get_user_pages(current, current->mm, virtp, nr_pages, 1, |
223 | 0, &pages, NULL); | 225 | 0, &pages, NULL); |