Skip to contentSkip to conversation

mm/mremap: Fix vma iterator initialization

PATCH New Liam R. Howlett 1 participant 1 message Jan 26, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/mremap: Fix vma iterator initialization

The vma iterator location is incorrect when there is a failure in the move_vma() function which alters the address being modified.

Delay the initialization of the vma iterator until the address is stable.

---
 mm/mremap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Andrew,

This can be placed next to ("mm: change munmap splitting order and move_vma()") and squashed before sending upstream.

mm/mremap.c +2 -1
index 1bc81afd90de..6c7f49ab7d19 100644
@@ -585,7 +585,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
 	unsigned long hiwater_vm;
 	int err = 0;
 	bool need_rmap_locks;
-	VMA_ITERATOR(vmi, mm, old_addr);
+	struct vma_iterator vmi;
 
 	/*
 	 * We'd prefer to avoid failure later on in do_munmap:
@@ -701,6 +701,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
 		return new_addr;
 	}
 
+	vma_iter_init(&vmi, mm, old_addr);
 	if (do_vmi_munmap(&vmi, mm, old_addr, old_len, uf_unmap, false) < 0) {
 		/* OOM: unable to split vma, just get accounts right */
 		if (vm_flags & VM_ACCOUNT && !(flags & MREMAP_DONTUNMAP))
Signature · 1 line
2.39.0