Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9164149ybi; Tue, 23 Jul 2019 23:07:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQOsG5w5qwA56hL+cX5iWJSMjjIYsy0H+KB2XzpRZgXjaNhyRqdpCWyvCCTgKyTABmO3Yx X-Received: by 2002:a17:902:2de4:: with SMTP id p91mr53292337plb.28.1563948444814; Tue, 23 Jul 2019 23:07:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948444; cv=none; d=google.com; s=arc-20160816; b=wntULgnjGU/JFYeJOvfmwBbIfGvTaZndFp3ts9Ikw8errR1T4fOHpaRCKkZpmlH0AP 3ZjtHRPWZ0B/nTWd2jocp2JhjhSuVNty9fZ0ic0UcP927pRIdgOOOG62crzTnxL/ucTR +4URdTyX3jsS4etks7iU1SRmQ72TqUq2yrzUjdmPKM7c0rO00y53HFStEEo7vSS4QDjn iVYtYE8REENRT4Hm6nK3vnG06kWGiYl11g7Qu6xFLXDfETIZdYgb5GguLBKtD3a55L7Q yvO+d/ypyypOZC8P6rfBfA98uPPz8bqnkiBkgOpIHxMjVRyi6HcicdpYYOpJ1aQtGSlf xgUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eym0BMHdbArtu9uPr+EyfIeUu2p0S0z5kNpGctDciqY=; b=W3cVEgkvZbAddB+E8iveXRhskdD9k5j8FP7kvZGSFSjv4meoPcJJXhESDc235jV796 3IvQ/SAn3qYQ2E6udB6f0PXT0qWbTWCG57R/up6fG51OZFFJL1yWP2l7GFb2n4FidPez w5t+Syr/UaN159eszM4jvvYgwI2lFv3EBMr3h3kBLIQQ2VVnRcLyB3CaWtCvX/6cy3QN Bn61nGV9pLM0tfF/Fnor5+O8bA83MZiOXu0cstyk1bWAlHHJ2uZTyU6bZHjFT/nnnqCQ EvwVKMLBRrkYeENUzwbTNalQyvU46ZOqi4dyyIPv9l887qjtTurRxPC2Nm1H5xcZMGzU g7Tg== 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 i127si12755004pfc.177.2019.07.23.23.07.09; Tue, 23 Jul 2019 23:07:24 -0700 (PDT) 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 S1726444AbfGXGFm (ORCPT + 99 others); Wed, 24 Jul 2019 02:05:42 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:41695 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbfGXGFi (ORCPT ); Wed, 24 Jul 2019 02:05:38 -0400 X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 7E8472000C; Wed, 24 Jul 2019 06:05:32 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH REBASE v4 06/14] arm: Properly account for stack randomization and stack guard gap Date: Wed, 24 Jul 2019 01:58:42 -0400 Message-Id: <20190724055850.6232-7-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit takes care of stack randomization and stack guard gap when computing mmap base address and checks if the task asked for randomization. This fixes the problem uncovered and not fixed for arm here: https://lkml.kernel.org/r/20170622200033.25714-1-riel@redhat.com Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook --- arch/arm/mm/mmap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index f866870db749..bff3d00bda5b 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -18,8 +18,9 @@ (((pgoff)<> (PAGE_SHIFT - 12)) static int mmap_is_legacy(struct rlimit *rlim_stack) { @@ -35,6 +36,15 @@ static int mmap_is_legacy(struct rlimit *rlim_stack) static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) { unsigned long gap = rlim_stack->rlim_cur; + unsigned long pad = stack_guard_gap; + + /* Account for stack randomization if necessary */ + if (current->flags & PF_RANDOMIZE) + pad += (STACK_RND_MASK << PAGE_SHIFT); + + /* Values close to RLIM_INFINITY can overflow. */ + if (gap + pad > gap) + gap += pad; if (gap < MIN_GAP) gap = MIN_GAP; -- 2.20.1