diff options
-rw-r--r-- | mm/mmap.c | 4 | ||||
-rw-r--r-- | mm/rmap.c | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/mm/mmap.c b/mm/mmap.c index 38dec592f496..0c144ec8c810 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -751,10 +751,8 @@ again: remove_next = 1 + (end > next->vm_end); importer->anon_vma = exporter->anon_vma; error = anon_vma_clone(importer, exporter); - if (error) { - importer->anon_vma = NULL; + if (error) return error; - } } } diff --git a/mm/rmap.c b/mm/rmap.c index ab8e7984fa19..e84beb4dcfce 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -287,6 +287,13 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) return 0; enomem_failure: + /* + * dst->anon_vma is dropped here otherwise its degree can be incorrectly + * decremented in unlink_anon_vmas(). + * We can safely do this because callers of anon_vma_clone() don't care + * about dst->anon_vma if anon_vma_clone() failed. + */ + dst->anon_vma = NULL; unlink_anon_vmas(dst); return -ENOMEM; } |