Re: [PATCH] vma: Detect infinite loop in vma tree
From: Vlastimil Babka
Date: Thu Oct 31 2024 - 13:07:46 EST
On 10/31/24 18:01, Liam R. Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>
>
> 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.
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> Cc: Vlastimil Babka <vbabka@xxxxxxx>
> Cc: Jann Horn <jannh@xxxxxxxxxx>
> ---
> mm/vma.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index 68138e8c153e..60ed8cc187ad 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -615,7 +615,8 @@ void validate_mm(struct mm_struct *mm)
> anon_vma_unlock_read(anon_vma);
> }
> #endif
> - i++;
> + if (++i > mm->map_count)
> + break;
Would it make sense to allow some slack so that the error below can
distinguish better between off-by-one/few error from a complete corruption?
And in that case assign some special value to "i" (-1?) to make it clear
this was triggered?
> }
> if (i != mm->map_count) {
> pr_emerg("map_count %d vma iterator %d\n", mm->map_count, i);