Skip to content

Commit b951242

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

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎arch/blackfin/kernel/ptrace.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,20 @@ put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
117117
int
118118
is_user_addr_valid(struct task_struct *child, unsigned long start, unsigned long len)
119119
{
120+
bool valid;
120121
struct vm_area_struct *vma;
121122
struct sram_list_struct *sraml;
122123

123124
/* overflow */
124125
if (start + len < start)
125126
return -EIO;
126127

128+
down_read(&child->mm->mmap_sem);
127129
vma = find_vma(child->mm, start);
128-
if (vma && start >= vma->vm_start && start + len <= vma->vm_end)
129-
return 0;
130+
valid = vma && start >= vma->vm_start && start + len <= vma->vm_end;
131+
up_read(&child->mm->mmap_sem);
132+
if (valid)
133+
return 0;
130134

131135
for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next)
132136
if (start >= (unsigned long)sraml->addr

0 commit comments

Comments
 (0)