copy_vma() ignores the result of vm_ops->open(). Discard the new VMA if it fails, without calling vm_ops->close() for it. The caller reports -ENOMEM for a NULL return, and the page tables of this VMA haven't moved yet. Signed-off-by: Josef Bacik --- mm/vma.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 212c2497bad4..b2e897a301b6 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2082,10 +2082,10 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, goto out_free_vma; if (anon_vma_clone(new_vma, vma, VMA_OP_REMAP)) goto out_free_mempol; + if (vma_open(new_vma)) + goto out_unlink_anon; if (new_vma->vm_file) get_file(new_vma->vm_file); - if (new_vma->vm_ops && new_vma->vm_ops->open) - new_vma->vm_ops->open(new_vma); if (vma_link(mm, new_vma)) goto out_vma_link; *need_rmap_locks = false; @@ -2098,7 +2098,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, if (new_vma->vm_file) fput(new_vma->vm_file); - +out_unlink_anon: unlink_anon_vmas(new_vma); out_free_mempol: mpol_put(vma_policy(new_vma)); -- 2.55.0