summaryrefslogtreecommitdiffstats
path: root/mm/vma.c
diff options
context:
space:
mode:
authorLiam R. Howlett <Liam.Howlett@Oracle.com>2024-10-31 20:36:08 +0100
committerAndrew Morton <akpm@linux-foundation.org>2024-11-11 22:09:42 +0100
commit8e1817b6ba97c3d92d163447226cf6a0c1f90723 (patch)
treed056f392ad5e593f537b516f4d404bb1f336a948 /mm/vma.c
parentselftests/mm: skip virtual_address_range tests on riscv (diff)
downloadlinux-8e1817b6ba97c3d92d163447226cf6a0c1f90723.tar.xz
linux-8e1817b6ba97c3d92d163447226cf6a0c1f90723.zip
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. [akpm@linux-foundation.org: add comment] Link: https://lkml.kernel.org/r/20241031193608.1965366-1-Liam.Howlett@oracle.com Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Jann Horn <jannh@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/vma.c')
-rw-r--r--mm/vma.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/mm/vma.c b/mm/vma.c
index 68138e8c153e..8a454a7bbc80 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -615,7 +615,11 @@ void validate_mm(struct mm_struct *mm)
anon_vma_unlock_read(anon_vma);
}
#endif
- i++;
+ /* Check for a infinite loop */
+ if (++i > mm->map_count + 10) {
+ i = -1;
+ break;
+ }
}
if (i != mm->map_count) {
pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);