From: Michel Lespinasse Date: Mon, 8 Oct 2012 23:30:01 +0000 (-0700) Subject: mm: fix potential anon_vma locking issue in mprotect() X-Git-Tag: upstream/snapshot3+hdmi~6473^2~124 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca42b26ab285edc5ee3f9faa48379d258db53c35;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git mm: fix potential anon_vma locking issue in mprotect() 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 Reviewed-by: Andrea Arcangeli Acked-by: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/mmap.c b/mm/mmap.c index 2ba2743..e3c365f 100644 --- 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);