Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750965AbdFTEkZ (ORCPT ); Tue, 20 Jun 2017 00:40:25 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:36099 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbdFTEkY (ORCPT ); Tue, 20 Jun 2017 00:40:24 -0400 Date: Mon, 19 Jun 2017 21:40:15 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Linus Torvalds cc: Hugh Dickins , Dave Jones , Linux Kernel Mailing List , Oleg Nesterov , Michal Hocko Subject: Re: Linux 4.12-rc6 In-Reply-To: Message-ID: References: <20170620002612.bwjphlk2qz3ynghl@codemonkey.org.uk> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2408 Lines: 62 On Mon, 19 Jun 2017, Hugh Dickins wrote: > On Tue, 20 Jun 2017, Linus Torvalds wrote: > > On Tue, Jun 20, 2017 at 8:26 AM, Dave Jones wrote: > > > > Hugh Dickins (1): > > > > mm: larger stack guard gap, between vmas > > > > > > This seems to be buggered. ... > > > > So maybe that "goto found" condition should have an additional test > > for "gap_end > gap_start"? > > > > Or maybe I'm just hallucinating and missed something. Hugh, Oleg, > > Michal, can you take another look and double-check this logic? > > My first impression is that you've got right to the heart of it, > before I even started looking. I'll go over that area more carefully > now, in case there are other such instances, and post a test patch > for Dave perhaps to try - but probably he's shut down now, so I'll > then grab a trinity, and see what luck I have with it. I've added nothing to your understanding: apart from general unease about whether MAP_FIXED can push us into corners I hadn't expected. I had originally wanted to add some more checks into DEBUG_VM_RB's browse_rb(); but realized then that MAP_FIXED is perfectly entitled to burst through the usual stack gaps I'd wanted to check there. And I wonder if trinity will discover more issues with those final adjustments at the end of unmapped_area[_topdowni](). But enough of deliberation, I'll get my trinity and try out the patch you suggested below. After a break. Hugh --- mm/mmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- 4.12-rc6/mm/mmap.c 2017-06-19 09:06:10.035407505 -0700 +++ linux/mm/mmap.c 2017-06-19 21:09:28.616707311 -0700 @@ -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 */