Skip to content

Commit

Permalink
mm: fix potential anon_vma locking issue in mprotect()
Browse files Browse the repository at this point in the history
Fix an anon_vma locking issue in the following situation:

- vma has no anon_vma
- next has an anon_vma
- vma is being shrunk / next is being expanded, due to an mprotect call

We need to take next's anon_vma lock to avoid races with rmap users (such
as page migration) while next is being expanded.

Signed-off-by: Michel Lespinasse <walken@google.com>
Reviewed-by: Andrea Arcangeli <aarcange@redhat.com>
Acked-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Michel Lespinasse authored and Linus Torvalds committed Oct 9, 2012
1 parent 227e404 commit ca42b26
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,12 @@ again: remove_next = 1 + (end > next->vm_end);
*/
if (vma->anon_vma && (importer || start != vma->vm_start)) {
anon_vma = vma->anon_vma;
VM_BUG_ON(adjust_next && next->anon_vma &&
anon_vma != next->anon_vma);
} else if (adjust_next && next->anon_vma)
anon_vma = next->anon_vma;
if (anon_vma)
anon_vma_lock(anon_vma);
}

if (root) {
flush_dcache_mmap_lock(mapping);
Expand Down

0 comments on commit ca42b26

Please sign in to comment.