vma: Detect infinite loop in vma tree
Subsystems (2)
PATCH v2 1/1 vma: Detect infinite loop in vma tree
From: "Liam R. Howlett" <[email protected]>
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.
--- mm/vma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/vma.c +4 -1
@@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma); }#endif - i++; +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);
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 22 lines · On Thu, 31 Oct 2024 15:36:08 -0400 "Liam R. Howlett" <[email protected]>…
From: "Liam R. Howlett" <[email protected]>
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.
...
+++
b/mm/vma.c(quoted diff) +0
-0@@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma);
Review void validate_mm(struct mm_struct *mm) · line 624
Quoted 10 lines
(quoted diff) +4
-1} #endif - i++; + 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);
It might be helpful to tell readers what's going on here?
mm/vma.c renamed from mm/vma.c~vma-detect-infinite-loop-in-vma-tree-fix +1 -0
@@ -615,6 +615,7 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma); }#endif +/* Check for a infinite loop */ if (++i > mm->map_count +10 ) { i =-1 ;break ;
_
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Thu, 31 Oct 2024 15:36:08 -0400 "Liam R. Howlett" <[email protected]>…
From: "Liam R. Howlett" <[email protected]>
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.
...
Quoted 15 lines
Review void validate_mm(struct mm_struct *mm) · line 624
Quoted 13 lines
+++
b/mm/vma.c(quoted diff) +4
-1@@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma); } #endif - i++; + 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);It might be helpful to tell readers what's going on here?
Sounds good. I guess I should have waited longer for a v2.
Quoted 13 lines
mm/vma.c renamed from mm/vma.c~vma-detect-infinite-loop-in-vma-tree-fix +1
-0@@ -615,6 +615,7 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma); }#endif +/* Check for a infinite loop */ if (++i > mm->map_count +10 ) { i =-1 ;break ;_
Quoted 31 lines · Liam R. Howlett
From: "Liam R. Howlett" <[email protected]>
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.
Signed-off-by Liam R. Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Jann Horn <[email protected]>--- mm/vma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)mm/vma.c +0
-0@@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm)anon_vma_unlock_read (anon_vma);
mm/vma.c void validate_mm(struct mm_struct *mm) · line 624
Quoted 10 lines
mm/vma.c +4
-1}#endif - i++; +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);
Signature · 3 lines
Cheers, David / dhildenb
Quoted 14 lines · Liam R. Howlett
From: "Liam R. Howlett" <[email protected]>
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.
Quoted 7 lines
Note that the mmap lock is held to ensure a consistent tree state during the validation process.
Signed-off-by Liam R. Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Jann Horn <[email protected]>
Quoted 20 lines
--- mm/vma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)mm/vma.c +4
-1@@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma); }#endif - i++; +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);
Quoted 10 lines · Liam R. Howlett
From: "Liam R. Howlett" <[email protected]>
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.
Quoted 8 lines
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.
Signed-off-by Liam R. Howlett <[email protected]>
Quoted 26 lines
Cc Lorenzo Stoakes <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Jann Horn <[email protected]>--- mm/vma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)mm/vma.c +4
-2@@ -615,7 +615,10 @@ void validate_mm(struct mm_struct *mm) anon_vma_unlock_read(anon_vma); }#endif - i++; +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); --2.43.0