提交 55ee64b3 编写于 作者: A Al Viro 提交者: Mauro Carvalho Chehab

[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: NAl 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: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 a0a030bd
...@@ -205,19 +205,21 @@ static u32 omap_vout_uservirt_to_phys(u32 virtp) ...@@ -205,19 +205,21 @@ static u32 omap_vout_uservirt_to_phys(u32 virtp)
struct vm_area_struct *vma; struct vm_area_struct *vma;
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
vma = find_vma(mm, virtp);
/* For kernel direct-mapped memory, take the easy way */ /* For kernel direct-mapped memory, take the easy way */
if (virtp >= PAGE_OFFSET) { if (virtp >= PAGE_OFFSET)
physp = virt_to_phys((void *) virtp); return virt_to_phys((void *) virtp);
} else if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
down_read(&current->mm->mmap_sem);
vma = find_vma(mm, virtp);
if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
/* this will catch, kernel-allocated, mmaped-to-usermode /* this will catch, kernel-allocated, mmaped-to-usermode
addresses */ addresses */
physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start); physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start);
up_read(&current->mm->mmap_sem);
} else { } else {
/* otherwise, use get_user_pages() for general userland pages */ /* otherwise, use get_user_pages() for general userland pages */
int res, nr_pages = 1; int res, nr_pages = 1;
struct page *pages; struct page *pages;
down_read(&current->mm->mmap_sem);
res = get_user_pages(current, current->mm, virtp, nr_pages, 1, res = get_user_pages(current, current->mm, virtp, nr_pages, 1,
0, &pages, NULL); 0, &pages, NULL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册