Received: by 10.223.176.5 with SMTP id f5csp3396850wra; Mon, 29 Jan 2018 12:35:09 -0800 (PST) X-Google-Smtp-Source: AH8x225qS5bFPww2onZbNxMZQLqvsRZ6Uu/a9MbPt1XsO5K4AcV4JXvjBP5DLugogPXBmLA85Dwd X-Received: by 2002:a17:902:6bc3:: with SMTP id m3-v6mr22801557plt.442.1517258109517; Mon, 29 Jan 2018 12:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517258109; cv=none; d=google.com; s=arc-20160816; b=LWxgZQKzgp2nOfhqXV6AQ+/IJb8x5ROrcf3xGUzlpZFQNRAXg6/UjlJc1XJCwtXNBi lZv7O/mIZgcoVRI2egZZyt6yA9MjgpjTKrgXufK9BzI+HYD0VrmOO+54+KbgRMQPetUC 07iy5jX/Qxw7FY6jPz2HbbgWsfeeXLzZkJA6geyd2X9TgzDgwV+lNPnRPLtupCJqETOa +F2wPXXYbiVv2ydMfyhPUQwD1VS4jj/ZmrArYpvsWhSOUP6IsAQWuZXDJeAFAgvhTE3W XYOxYgUAm8SW0r8Ga2MAt4FjGCqhBayucc/SCoKVCG/2P0OwCB86gW6aiaZqU1C7D1oD CeHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+sQKaV84S4lWFRV9Xq2Ay55OhqLj7OEQQ9Mp/IAvBgA=; b=SlBBmbs3nwdv655swF4h7ckzk+3c7tS1RvnSOsR1mebh0g1wDoIL7MY0Xt6+j7zzr3 b5dmakbLQZaJgr37PQHki32KK9PJLV08do5o0hZrp5VSz/Rbx19jctGyhePVky9kk9p3 x6iqp1CATMGnCkrTcN7DPIEvDLLJ82Z1V+jHLR8oa2HCNpT7J5vxS+uuq/T3yoPPvQHS IPiuvf2B3KgLjW+33TwgPLsgvuIvtuPq5/GPL6qaZIRjzZDHulO66C1nqFdlb32xaxPZ 5IQiIy/EVGrfd7Llyrh9lC8vGpZT7JZfX58IH6wSk2Z8d3+7jvoXKm0hON/OchVM7l2t 3phg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b11-v6si2506061plr.8.2018.01.29.12.34.54; Mon, 29 Jan 2018 12:35:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932342AbeA2Ueb (ORCPT + 99 others); Mon, 29 Jan 2018 15:34:31 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40488 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754221AbeA2UOf (ORCPT ); Mon, 29 Jan 2018 15:14:35 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 18DA62F5D; Mon, 29 Jan 2018 13:04:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Hocko , Ben Hutchings , Willy Tarreau , Oleg Nesterov , Rik van Riel , Hugh Dickins , Andrew Morton , Linus Torvalds Subject: [PATCH 4.9 13/66] mm/mmap.c: do not blow on PROT_NONE MAP_FIXED holes in the stack Date: Mon, 29 Jan 2018 13:56:37 +0100 Message-Id: <20180129123840.529040411@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123839.842860149@linuxfoundation.org> References: <20180129123839.842860149@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Hocko commit 561b5e0709e4a248c67d024d4d94b6e31e3edf2f upstream. Commit 1be7107fbe18 ("mm: larger stack guard gap, between vmas") has introduced a regression in some rust and Java environments which are trying to implement their own stack guard page. They are punching a new MAP_FIXED mapping inside the existing stack Vma. This will confuse expand_{downwards,upwards} into thinking that the stack expansion would in fact get us too close to an existing non-stack vma which is a correct behavior wrt safety. It is a real regression on the other hand. Let's work around the problem by considering PROT_NONE mapping as a part of the stack. This is a gros hack but overflowing to such a mapping would trap anyway an we only can hope that usespace knows what it is doing and handle it propely. Fixes: 1be7107fbe18 ("mm: larger stack guard gap, between vmas") Link: http://lkml.kernel.org/r/20170705182849.GA18027@dhcp22.suse.cz Signed-off-by: Michal Hocko Debugged-by: Vlastimil Babka Cc: Ben Hutchings Cc: Willy Tarreau Cc: Oleg Nesterov Cc: Rik van Riel Cc: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2240,7 +2240,8 @@ int expand_upwards(struct vm_area_struct gap_addr = TASK_SIZE; next = vma->vm_next; - if (next && next->vm_start < gap_addr) { + if (next && next->vm_start < gap_addr && + (next->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) { if (!(next->vm_flags & VM_GROWSUP)) return -ENOMEM; /* Check that both stack segments have the same anon_vma? */ @@ -2324,7 +2325,8 @@ int expand_downwards(struct vm_area_stru if (gap_addr > address) return -ENOMEM; prev = vma->vm_prev; - if (prev && prev->vm_end > gap_addr) { + if (prev && prev->vm_end > gap_addr && + (prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) { if (!(prev->vm_flags & VM_GROWSDOWN)) return -ENOMEM; /* Check that both stack segments have the same anon_vma? */