mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
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 <[email protected]> Reviewed-by: Rik van Riel <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Pete Zaitcev <[email protected]> Cc: Borislav Petkov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
93b4a44f3a
commit
31f2b0ebc0
1 changed files with 5 additions and 4 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue