Skip to content

Commit 92b7399

Browse files
howlettakpm00
authored andcommitted
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/[email protected] Fixes: 524e00b ("mm: remove rb tree") Signed-off-by: Liam R. Howlett <[email protected]> Reported-by: Lukas Bulwahn <[email protected]> Tested-by: Lukas Bulwahn <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7efc3b7 commit 92b7399

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mm/mmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
32403240
out_vma_link:
32413241
if (new_vma->vm_ops && new_vma->vm_ops->close)
32423242
new_vma->vm_ops->close(new_vma);
3243+
3244+
if (new_vma->vm_file)
3245+
fput(new_vma->vm_file);
3246+
3247+
unlink_anon_vmas(new_vma);
32433248
out_free_mempol:
32443249
mpol_put(vma_policy(new_vma));
32453250
out_free_vma:

0 commit comments

Comments
 (0)