Commit cdc02631 authored by Daniel Forrest's avatar Daniel Forrest Committed by Jiri Slaby

mm: fix anon_vma_clone() error treatment

commit c4ea95d7 upstream.

Andrew Morton noticed that the error return from anon_vma_clone() was
being dropped and replaced with -ENOMEM (which is not itself a bug
because the only error return value from anon_vma_clone() is -ENOMEM).

I did an audit of callers of anon_vma_clone() and discovered an actual
bug where the error return was being lost.  In __split_vma(), between
Linux 3.11 and 3.12 the code was changed so the err variable is used
before the call to anon_vma_clone() and the default initial value of
-ENOMEM is overwritten.  So a failure of anon_vma_clone() will return
success since err at this point is now zero.

Below is a patch which fixes this bug and also propagates the error
return value from anon_vma_clone() in all cases.

Fixes: ef0855d3 ("mm: mempolicy: turn vma_set_policy() into vma_dup_policy()")
Signed-off-by: default avatarDaniel Forrest <dan.forrest@ssec.wisc.edu>
Reviewed-by: default avatarMichal Hocko <mhocko@suse.cz>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Tim Hartrick <tim@edgecast.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 0315eaed
...@@ -746,8 +746,11 @@ again: remove_next = 1 + (end > next->vm_end); ...@@ -746,8 +746,11 @@ again: remove_next = 1 + (end > next->vm_end);
* shrinking vma had, to cover any anon pages imported. * shrinking vma had, to cover any anon pages imported.
*/ */
if (exporter && exporter->anon_vma && !importer->anon_vma) { if (exporter && exporter->anon_vma && !importer->anon_vma) {
if (anon_vma_clone(importer, exporter)) int error;
return -ENOMEM;
error = anon_vma_clone(importer, exporter);
if (error)
return error;
importer->anon_vma = exporter->anon_vma; importer->anon_vma = exporter->anon_vma;
} }
} }
...@@ -2419,7 +2422,8 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma, ...@@ -2419,7 +2422,8 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
if (err) if (err)
goto out_free_vma; goto out_free_vma;
if (anon_vma_clone(new, vma)) err = anon_vma_clone(new, vma);
if (err)
goto out_free_mpol; goto out_free_mpol;
if (new->vm_file) if (new->vm_file)
......
...@@ -274,6 +274,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) ...@@ -274,6 +274,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
{ {
struct anon_vma_chain *avc; struct anon_vma_chain *avc;
struct anon_vma *anon_vma; struct anon_vma *anon_vma;
int error;
/* Don't bother if the parent process has no anon_vma here. */ /* Don't bother if the parent process has no anon_vma here. */
if (!pvma->anon_vma) if (!pvma->anon_vma)
...@@ -283,8 +284,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) ...@@ -283,8 +284,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
* First, attach the new VMA to the parent VMA's anon_vmas, * First, attach the new VMA to the parent VMA's anon_vmas,
* so rmap can find non-COWed pages in child processes. * so rmap can find non-COWed pages in child processes.
*/ */
if (anon_vma_clone(vma, pvma)) error = anon_vma_clone(vma, pvma);
return -ENOMEM; if (error)
return error;
/* Then add our own anon_vma. */ /* Then add our own anon_vma. */
anon_vma = anon_vma_alloc(); anon_vma = anon_vma_alloc();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment