Commit 92b73996 authored by Liam Howlett's avatar Liam Howlett Committed by Andrew Morton

mmap: fix copy_vma() failure path

The anon vma was not unlinked and the file was not closed in the failure
path when the machine runs out of memory during the maple tree
modification.  This caused a memory leak of the anon vma chain and vma
since neither would be freed.

Link: https://lkml.kernel.org/r/20221011203621.1446507-1-Liam.Howlett@oracle.com
Fixes: 524e00b3 ("mm: remove rb tree")
Signed-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Reported-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
Tested-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 7efc3b72
...@@ -3240,6 +3240,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, ...@@ -3240,6 +3240,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
out_vma_link: out_vma_link:
if (new_vma->vm_ops && new_vma->vm_ops->close) if (new_vma->vm_ops && new_vma->vm_ops->close)
new_vma->vm_ops->close(new_vma); new_vma->vm_ops->close(new_vma);
if (new_vma->vm_file)
fput(new_vma->vm_file);
unlink_anon_vmas(new_vma);
out_free_mempol: out_free_mempol:
mpol_put(vma_policy(new_vma)); mpol_put(vma_policy(new_vma));
out_free_vma: out_free_vma:
......
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