Skip to contentSkip to conversation

fs/userfaultfd: Fix vma iteration in mas_for_each() loop

PATCH New Liam Howlett 1 participant 1 message Jun 15, 2022

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

PATCH 1/1 fs/userfaultfd: Fix vma iteration in mas_for_each() loop

The maple tree state becomes stale when the tree is altered and requires the iteration to be paused with mas_pause(). This forces the next iteration to start from the top of tree for the next entry.

Reported-by [email protected]
Fixes d3ccd17e7c96 ("mm: start tracking VMAs with maple tree")
---
 fs/userfaultfd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/userfaultfd.c +5 -2
index d18500633ebe..d398f6bf6d74 100644
@@ -886,10 +886,13 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
 				 vma->vm_file, vma->vm_pgoff,
 				 vma_policy(vma),
 				 NULL_VM_UFFD_CTX, anon_vma_name(vma));
-		if (prev)
+		if (prev) {
+			mas_pause(&mas);
 			vma = prev;
-		else
+		} else {
 			prev = vma;
+		}
+
 		vma->vm_flags = new_flags;
 		vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
 	}
Signature · 1 line
2.35.1