From: Lorenzo Stoakes Date: Sun, 30 Mar 2025 16:20:48 +0000 (+0100) Subject: mm/mremap: do not set vrm->vma NULL immediately prior to checking it X-Git-Tag: v6.15-rc1~38^2~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36eed5400805b294f1df39b0e3ebc5b7971b3c16;p=thirdparty%2Fkernel%2Fstable.git mm/mremap: do not set vrm->vma NULL immediately prior to checking it This seems rather unwise. If we cannot merge, extend, then we need to recall the original VMA to see if we need to uncharge. If we do need to, do so. Link: https://lkml.kernel.org/r/b2fb6b9c-376d-4e9b-905e-26d847fd3865@lucifer.local Fixes: d5c8aec0542e ("mm/mremap: initial refactor of move_vma()") Signed-off-by: Lorenzo Stoakes Reported-=by: "Lai, Yi" Closes: https://lore.kernel.org/linux-mm/Z+lcvEIHMLiKVR1i@ly-workstation/ Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Harry Yoo Signed-off-by: Andrew Morton --- diff --git a/mm/mremap.c b/mm/mremap.c index 0865387531ed8..7db9da609c84f 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -1561,11 +1561,12 @@ static unsigned long expand_vma_in_place(struct vma_remap_struct *vrm) * adjacent to the expanded vma and otherwise * compatible. */ - vma = vrm->vma = vma_merge_extend(&vmi, vma, vrm->delta); + vma = vma_merge_extend(&vmi, vma, vrm->delta); if (!vma) { vrm_uncharge(vrm); return -ENOMEM; } + vrm->vma = vma; vrm_stat_account(vrm, vrm->delta);