m68k: call find_vma with the mmap_sem held in sys_cacheflush()

Performing vma lookups without taking the mm->mmap_sem is asking for
trouble.  While doing the search, the vma in question can be modified or
even removed before returning to the caller.  Take the lock (shared) in
order to avoid races while iterating through the vmacache and/or rbtree.
In addition, this guarantees that the address space will remain intact
during the CPU flushing.

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Davidlohr Bueso 2014-10-09 15:29:45 -07:00 committed by Linus Torvalds
parent 7cc36bbddd
commit cd2567b685

View file

@ -376,7 +376,6 @@ cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
asmlinkage int asmlinkage int
sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len) sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
{ {
struct vm_area_struct *vma;
int ret = -EINVAL; int ret = -EINVAL;
if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL || if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL ||
@ -389,17 +388,21 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
goto out; goto out;
} else { } else {
struct vm_area_struct *vma;
/* Check for overflow. */
if (addr + len < addr)
goto out;
/* /*
* Verify that the specified address region actually belongs * Verify that the specified address region actually belongs
* to this process. * to this process.
*/ */
vma = find_vma (current->mm, addr);
ret = -EINVAL; ret = -EINVAL;
/* Check for overflow. */ down_read(&current->mm->mmap_sem);
if (addr + len < addr) vma = find_vma(current->mm, addr);
goto out; if (!vma || addr < vma->vm_start || addr + len > vma->vm_end)
if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) goto out_unlock;
goto out;
} }
if (CPU_IS_020_OR_030) { if (CPU_IS_020_OR_030) {
@ -429,7 +432,7 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
__asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr)); __asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
} }
ret = 0; ret = 0;
goto out; goto out_unlock;
} else { } else {
/* /*
* 040 or 060: don't blindly trust 'scope', someone could * 040 or 060: don't blindly trust 'scope', someone could
@ -446,6 +449,8 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
ret = cache_flush_060 (addr, scope, cache, len); ret = cache_flush_060 (addr, scope, cache, len);
} }
} }
out_unlock:
up_read(&current->mm->mmap_sem);
out: out:
return ret; return ret;
} }