Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

blackfin/ptrace: call find_vma with the mmap_sem held

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.

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Cc: Steven Miao <realmz6@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Davidlohr Bueso and committed by
Linus Torvalds
b951242a cccad5b9

+6 -2
+6 -2
arch/blackfin/kernel/ptrace.c
··· 117 117 int 118 118 is_user_addr_valid(struct task_struct *child, unsigned long start, unsigned long len) 119 119 { 120 + bool valid; 120 121 struct vm_area_struct *vma; 121 122 struct sram_list_struct *sraml; 122 123 ··· 125 124 if (start + len < start) 126 125 return -EIO; 127 126 127 + down_read(&child->mm->mmap_sem); 128 128 vma = find_vma(child->mm, start); 129 - if (vma && start >= vma->vm_start && start + len <= vma->vm_end) 130 - return 0; 129 + valid = vma && start >= vma->vm_start && start + len <= vma->vm_end; 130 + up_read(&child->mm->mmap_sem); 131 + if (valid) 132 + return 0; 131 133 132 134 for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next) 133 135 if (start >= (unsigned long)sraml->addr