Skip to content

Commit 8e1817b

Browse files
howlettakpm00
authored andcommitted
vma: detect infinite loop in vma tree
There have been no reported infinite loops in the tree, but checking the detection of an infinite loop during validation is simple enough. Add the detection to the validate_mm() function so that error reports are clear and don't just report stalls. This does not protect against internal maple tree issues, but it does detect too many vmas being returned from the tree. The variance of +10 is to allow for the debugging output to be more useful for nearly correct counts. In the event of more than 10 over the map_count, the count will be set to -1 for easier identification of a potential infinite loop. Note that the mmap lock is held to ensure a consistent tree state during the validation process. [[email protected]: add comment] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Liam R. Howlett <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Cc: Jann Horn <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4175eff commit 8e1817b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mm/vma.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ void validate_mm(struct mm_struct *mm)
615615
anon_vma_unlock_read(anon_vma);
616616
}
617617
#endif
618-
i++;
618+
/* Check for a infinite loop */
619+
if (++i > mm->map_count + 10) {
620+
i = -1;
621+
break;
622+
}
619623
}
620624
if (i != mm->map_count) {
621625
pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);

0 commit comments

Comments
 (0)