Skip to content

Commit 1f2284f

Browse files
Hugh Dickinsgregkh
authored andcommitted
mm: fix new crash in unmapped_area_topdown()
commit f4cb767d76cf7ee72f97dd76f6cfa6c76a5edc89 upstream. Trinity gets kernel BUG at mm/mmap.c:1963! in about 3 minutes of mmap testing. That's the VM_BUG_ON(gap_end < gap_start) at the end of unmapped_area_topdown(). Linus points out how MAP_FIXED (which does not have to respect our stack guard gap intentions) could result in gap_end below gap_start there. Fix that, and the similar case in its alternative, unmapped_area(). Fixes: 1be7107fbe18 ("mm: larger stack guard gap, between vmas") Reported-by: Dave Jones <davej@codemonkey.org.uk> Debugged-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Michal Hocko <mhocko@suse.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f41512c commit 1f2284f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

mm/mmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,8 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
17711771
/* Check if current node has a suitable gap */
17721772
if (gap_start > high_limit)
17731773
return -ENOMEM;
1774-
if (gap_end >= low_limit && gap_end - gap_start >= length)
1774+
if (gap_end >= low_limit &&
1775+
gap_end > gap_start && gap_end - gap_start >= length)
17751776
goto found;
17761777

17771778
/* Visit right subtree if it looks promising */
@@ -1874,7 +1875,8 @@ unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
18741875
gap_end = vm_start_gap(vma);
18751876
if (gap_end < low_limit)
18761877
return -ENOMEM;
1877-
if (gap_start <= high_limit && gap_end - gap_start >= length)
1878+
if (gap_start <= high_limit &&
1879+
gap_end > gap_start && gap_end - gap_start >= length)
18781880
goto found;
18791881

18801882
/* Visit left subtree if it looks promising */

0 commit comments

Comments
 (0)