Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp176344yba; Wed, 17 Apr 2019 22:27:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3+7rsRtejO24/7MTOcphI9D1Yx22lcwgC4GZEUYrlmfI6VTlyoUluBkxoKJFwT8yfdPNZ X-Received: by 2002:a17:902:bd94:: with SMTP id q20mr4069987pls.334.1555565232925; Wed, 17 Apr 2019 22:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555565232; cv=none; d=google.com; s=arc-20160816; b=yy5g4IY119RyPLHnt3DiSTqsFtC7hjuMn4K6BeXh6wiaDj65JGPoX0930PNJcW8FaK mtG7wxInjO833LudHRBwiDPA3mVqnnGJSGHwZUCC4IpIHr5SrwnJHEuj2+AlEcWzQSY0 +i+FPqaLfTxlu5yoFlFzmlsQVsk10ahUF+p1ftLsd5pen6lpnp9PE/KSOz5FsL5cHZ9b uZFld7Ylw6+Y/DJ/lKVi3a9ky0dBUIpYP5RqbvqS5f/e0Riy5KvsMORhb4otfZ7tzX6h 8zU/WOoLbTS8Ni4CTTtBVK/W9IgvzShJtWOB3LlLDpVs1vmYhX/9EbDQud/ulart2e+T jB+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=KOswaRWRUemI8S/gquiofczxdNhkxEeSj4E8YC19lcI=; b=wtU7v1n7bXqb/KReJ8e/S/sWBBwJwtmitQfnSJhNTbCaBYwr3E+U3QX8ZbNoSF+tLq 6j/iJjq4V9Vk4dAqprjla0nNMzefbI6GIX6v/87GRlqTy88SaJiqB/KoYcxV2/s5H2Ol 68myr99gNr8h8I8FHEFZ6J4AGVlc3tYkq83pm+bPNtf2f7yJn4zHUpGwSIH0XKIOfZDL aEMpXk480OOd03xoso7YhLJL5c/+IRXG0LcqFAArd5Io/EmYAjhPVztu125B0Ex8ZCFJ srn+2kw62qRBi196NuWS24JuYmwHrMOcThRFHYyQ8nu8nM4j/jbO9jPdIk5NyDA+DOBI 0Pnw== 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 i3si967660pgh.458.2019.04.17.22.26.58; Wed, 17 Apr 2019 22:27:12 -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 S1731240AbfDRFYl (ORCPT + 99 others); Thu, 18 Apr 2019 01:24:41 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:56715 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbfDRFYl (ORCPT ); Thu, 18 Apr 2019 01:24:41 -0400 X-Originating-IP: 79.86.19.127 Received: from [192.168.0.11] (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 42730240002; Thu, 18 Apr 2019 05:24:33 +0000 (UTC) Subject: Re: [PATCH v3 03/11] arm64: Consider stack randomization for mmap base only when necessary To: Kees Cook Cc: Andrew Morton , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , LKML , linux-arm-kernel , linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, "linux-fsdevel@vger.kernel.org" , Linux-MM References: <20190417052247.17809-1-alex@ghiti.fr> <20190417052247.17809-4-alex@ghiti.fr> From: Alex Ghiti Message-ID: Date: Thu, 18 Apr 2019 01:24:32 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: sv-FI Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/18/19 12:37 AM, Kees Cook wrote: > On Wed, Apr 17, 2019 at 12:26 AM Alexandre Ghiti wrote: >> Do not offset mmap base address because of stack randomization if >> current task does not want randomization. > Maybe mention that this makes this logic match the existing x86 behavior too? Ok I will add this in case of a v4. > >> Signed-off-by: Alexandre Ghiti > Acked-by: Kees Cook Thanks ! > > -Kees > >> --- >> arch/arm64/mm/mmap.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c >> index ed4f9915f2b8..ac89686c4af8 100644 >> --- a/arch/arm64/mm/mmap.c >> +++ b/arch/arm64/mm/mmap.c >> @@ -65,7 +65,11 @@ unsigned long arch_mmap_rnd(void) >> static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) >> { >> unsigned long gap = rlim_stack->rlim_cur; >> - unsigned long pad = (STACK_RND_MASK << PAGE_SHIFT) + stack_guard_gap; >> + 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) >> -- >> 2.20.1 >> >