Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4273682ybi; Mon, 29 Jul 2019 22:59:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaccwY2EjuiC2jCR+UiHBJe5e6p/i2QQpfHYA1YzsgcEPLEnBDlt4kDW8bhTrX1WYlW26F X-Received: by 2002:a62:ac11:: with SMTP id v17mr40278849pfe.236.1564466378155; Mon, 29 Jul 2019 22:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466378; cv=none; d=google.com; s=arc-20160816; b=ZDL0GRyr+FR1IDlIHoZ3zy+nrfnbSdIcgoFUA6IklMuwbp4292ohsYNHiS+KwDFo6N +5OFgo8ab2aOcj56rK/NdPxjRAq2Jt++JUjzP+ww2HvSLycShVjRZQmt8pG8EAFiZayH Wi3vrxxT7zE35KWhm1Y2kIqROLHsMVXBpAxkUIVq+ZVI7KmeerbPPeOnFCg8zL/XpIDi Ccz05fIQpwT7ByH6MSy/coicQzOfG277QZgcicI4uuKUcJw1HapWHCA+WJHefw4tLfo+ gtI+ADE+eNEPIhFfNqCd2YcGrB2h+LCeC5ZtD5cDR0VHm9N1I7DrqW/URR7v9n9Wxi4F YN6g== 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=21mhY1F6D/bVN4FBUSB5kLGwxQH8yFVmkExK3y72E74=; b=AGJHjfTxWpSH3Hs9ty8u2T+09JuX44bUTB15nqPODOLPJsHVo5LiHzQLATxBM3mO7R K+eqOodZP2LYsyQWj9r0WMSVEdeB5UDlgT/wJVJvuXeGESi0THFo0wov2BfxausvOQEV 8FvjwiPiz0tLI8Hz55s+jJyec0kHFm+0/0Jt5TKfIARkC5njsZiJbqXg1UHQp6+5Gg+S B4iGAi7qBkv5JDFp8VoOrDNbmyX4th/WO+O6O5RJllcraRrrveeRcNHnVB+XARU5YVve xge0Zq2JITF+HHha+P/soSiXtlm54dFhLpw3uM6kkydeO1+bp5P1nwR8wiiGasR7jnpL auhw== 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 a89si29577037pla.60.2019.07.29.22.59.23; Mon, 29 Jul 2019 22:59:38 -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 S1728598AbfG3Fys (ORCPT + 99 others); Tue, 30 Jul 2019 01:54:48 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:55753 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbfG3Fys (ORCPT ); Tue, 30 Jul 2019 01:54:48 -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 A580220003; Tue, 30 Jul 2019 05:54:42 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , 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 v5 03/14] arm64: Consider stack randomization for mmap base only when necessary Date: Tue, 30 Jul 2019 01:51:02 -0400 Message-Id: <20190730055113.23635-4-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-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 Do not offset mmap base address because of stack randomization if current task does not want randomization. Note that x86 already implements this behaviour. Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- 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 bb0140afed66..e4acaead67de 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -54,7 +54,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