]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm: fix potential anon_vma locking issue in mprotect()
authorMichel Lespinasse <walken@google.com>
Fri, 7 Sep 2012 00:23:41 +0000 (10:23 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 7 Sep 2012 05:36:16 +0000 (15:36 +1000)
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>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c

index 07ae3776866b2e2506a7fb5814b9f5f535dd4b67..d6810b79607b1b03f8a1fb331f421fc8c87072b0 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -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);