Skip to content

Commit cd2567b

Browse files
Davidlohr Buesotorvalds
authored andcommitted
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>
1 parent 7cc36bb commit cd2567b

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎arch/m68k/kernel/sys_m68k.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
376376
asmlinkage int
377377
sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
378378
{
379-
struct vm_area_struct *vma;
380379
int ret = -EINVAL;
381380

382381
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)
389388
if (!capable(CAP_SYS_ADMIN))
390389
goto out;
391390
} else {
391+
struct vm_area_struct *vma;
392+
393+
/* Check for overflow. */
394+
if (addr + len < addr)
395+
goto out;
396+
392397
/*
393398
* Verify that the specified address region actually belongs
394399
* to this process.
395400
*/
396-
vma = find_vma (current->mm, addr);
397401
ret = -EINVAL;
398-
/* Check for overflow. */
399-
if (addr + len < addr)
400-
goto out;
401-
if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
402-
goto out;
402+
down_read(&current->mm->mmap_sem);
403+
vma = find_vma(current->mm, addr);
404+
if (!vma || addr < vma->vm_start || addr + len > vma->vm_end)
405+
goto out_unlock;
403406
}
404407

405408
if (CPU_IS_020_OR_030) {
@@ -429,7 +432,7 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
429432
__asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
430433
}
431434
ret = 0;
432-
goto out;
435+
goto out_unlock;
433436
} else {
434437
/*
435438
* 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)
446449
ret = cache_flush_060 (addr, scope, cache, len);
447450
}
448451
}
452+
out_unlock:
453+
up_read(&current->mm->mmap_sem);
449454
out:
450455
return ret;
451456
}

0 commit comments

Comments
 (0)