rmap: anon_vma_prepare() can leak anon_vma_chain

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Saturday, April 24, 2010 - 3:59 pm

Gitweb:     http://git.kernel.org/linus/31f2b0ebc01fd332cb0997f7ce9f9cde29af9e20
Commit:     31f2b0ebc01fd332cb0997f7ce9f9cde29af9e20
Parent:     93b4a44f3ad69520d605aace3f3486b8eb754b96
Author:     Oleg Nesterov <oleg@redhat.com>
AuthorDate: Fri Apr 23 13:18:01 2010 -0400
Committer:  Linus Torvalds <torvalds@linux-foundation.org>
CommitDate: Sat Apr 24 11:31:25 2010 -0700

    rmap: anon_vma_prepare() can leak anon_vma_chain
    
    If find_mergeable_anon_vma() succeeds but another thread installs
    ->anon_vma before we take ptl, then allocated == NULL but avc should be
    freed.  Change the code to check avc != NULL to detect this case.
    
    Also, a couple of whitespace changes to make the critical section more
    visible.
    
    Signed-off-by: Oleg Nesterov <oleg@redhat.com>
    Reviewed-by: Rik van Riel <riel@redhat.com>
    Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
    Cc: Pete Zaitcev <zaitcev@redhat.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 mm/rmap.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/rmap.c b/mm/rmap.c
index 526704e..07fc947 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -133,8 +133,8 @@ int anon_vma_prepare(struct vm_area_struct *vma)
 				goto out_enomem_free_avc;
 			allocated = anon_vma;
 		}
-		spin_lock(&anon_vma->lock);
 
+		spin_lock(&anon_vma->lock);
 		/* page_table_lock to protect against threads */
 		spin_lock(&mm->page_table_lock);
 		if (likely(!vma->anon_vma)) {
@@ -144,14 +144,15 @@ int anon_vma_prepare(struct vm_area_struct *vma)
 			list_add(&avc->same_vma, &vma->anon_vma_chain);
 			list_add(&avc->same_anon_vma, &anon_vma->head);
 			allocated = NULL;
+			avc = NULL;
 		}
 		spin_unlock(&mm->page_table_lock);
-
 		spin_unlock(&anon_vma->lock);
-		if (unlikely(allocated)) {
+
+		if (unlikely(allocated))
 			anon_vma_free(allocated);
+		if (unlikely(avc))
 			anon_vma_chain_free(avc);
-		}
 	}
 	return 0;
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
rmap: anon_vma_prepare() can leak anon_vma_chain, Linux Kernel Mailing ..., (Sat Apr 24, 3:59 pm)