Received: by 10.223.176.5 with SMTP id f5csp3407620wra; Mon, 29 Jan 2018 12:44:33 -0800 (PST) X-Google-Smtp-Source: AH8x226YdTWDOvcckvPeYAMiUi7DM/0xG//ZP5w1yKuE+l9NVqA1MFfHM/06NT5hi95yBkKK1xLV X-Received: by 10.98.233.10 with SMTP id j10mr27532319pfh.123.1517258673306; Mon, 29 Jan 2018 12:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517258673; cv=none; d=google.com; s=arc-20160816; b=VdDKlzm3rUZ3v3+NFaxGQVIH7LXulSh+/jwrx8gPQuqIG3GxZI6mMAUl5zKz9C6d/G nhRmcFvSlYbjiDYAnNudJUzNp5Pnoti57WUlXL+4XAoP1hKjEYazAxMwFvMTqISWjP6d Wb75PGg7T+Sr0V9P5YglBal9pspl03KMtSxRuRr/GXzy5th12cVxR82A669EXYu1b7eQ 0GjTViDtXHp8yFhXSsqAbd2cO5yh8oA1ojtB8mZ/Asame4YzmEzkgXYotMrsHLeTbHJ0 iXX1hF+1gAJY1jQznlCfPA0d/Vf4p2l6zdJgOu0R1CPvmc8/OfO8LxyOEREE1dCKE1/Y 9vww== 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=PsvwCGZbpFPSBcXw/fvGiirPHIlaK1eikqb1KJomKJo=; b=EMPpHMvsIRoVYtss7GIzdzgc+1hIn9eyhO1PPuYHeif5c1Zw+hsCssHG0eu+2HsZ9x oKd4Rb4fpWF0hO/3A33eyC7lac4RaPo0LO33G7FE1ePT5y8JA0eud6eIS48Zb104hfij 3VlrmO98nR+U6I0HRFcHXT7wsT8/cTLThDA0lyTbT764GEJmSyhoxkeC7dO8Zih5YIoj hjK+iy6VySjsOpHTmXMBxmVrA4POMDG+DFA4SAFs+yWvl4dhDYhkkf2Cp1Mpd+k1BNTy l+wMzEHT1MrBAf5KDbZha1Xx3886BH9thHpA991PK9j7Jb1SPEXPrAYOZH9ZVkRyN4CY HvbA== 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 f9-v6si376556plo.697.2018.01.29.12.44.18; Mon, 29 Jan 2018 12:44:33 -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 S1754067AbeA2Unu (ORCPT + 99 others); Mon, 29 Jan 2018 15:43:50 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35644 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752834AbeA2UMm (ORCPT ); Mon, 29 Jan 2018 15:12:42 -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 4B52E2F2B; Mon, 29 Jan 2018 13:03:00 +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.4 21/74] mm/mmap.c: do not blow on PROT_NONE MAP_FIXED holes in the stack Date: Mon, 29 Jan 2018 13:56:26 +0100 Message-Id: <20180129123848.581429861@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123847.507563674@linuxfoundation.org> References: <20180129123847.507563674@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.4-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 @@ -2188,7 +2188,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? */ @@ -2273,7 +2274,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? */