Author: Hugh Dickins Date: Mon, 19 Jun 2017 21:40:56 -0700 Description: mm: Guard against under-sized gap in unmapped_area{,_topdown}() Origin: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1426125.html --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1817,7 +1817,8 @@ unsigned long unmapped_area(struct vm_un /* Check if current node has a suitable gap */ if (gap_start > high_limit) return -ENOMEM; - if (gap_end >= low_limit && gap_end - gap_start >= length) + if (gap_end >= low_limit && + gap_end > gap_start && gap_end - gap_start >= length) goto found; /* Visit right subtree if it looks promising */ @@ -1920,7 +1921,8 @@ unsigned long unmapped_area_topdown(stru gap_end = vm_start_gap(vma); if (gap_end < low_limit) return -ENOMEM; - if (gap_start <= high_limit && gap_end - gap_start >= length) + if (gap_start <= high_limit && + gap_end > gap_start && gap_end - gap_start >= length) goto found; /* Visit left subtree if it looks promising */