Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2734533ybi; Sun, 26 May 2019 06:54:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxRx5NW9lEg87hmKKvlX6NfmmwmqIL+q7FtkRcW7fZ1B1yKdE2AF++8KLRFPykoMh1SJ1x X-Received: by 2002:a17:90a:9382:: with SMTP id q2mr24476364pjo.131.1558878867024; Sun, 26 May 2019 06:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558878867; cv=none; d=google.com; s=arc-20160816; b=bYD+LGJ/dXV1DBmwncWN+4kNM7yw2/Mf4NBNM1NdeI47zCq0sYpLC09ZKNRvwMmwSL SnquAM545WnGRAq1DBIQqbzC01AtE/xaApZv3/r15FSiFAL1NvZsXUQK64SbqijDnZ+w 9hRIhfVrUJpfx9YdJ/u0odV470u6URk16V0l8nVatB1xlwJPEXju0gX3xhAcVzNG7kue sbMFc64evn3BI1Y1h9J9rgaXH7dWx33HKNEQkx100t9GGU0FTOEQBktZJFl9grF+NHYg xtVKC9B2r/imY1t0H3P2/rm0+qaEcNEePoIrp1ZxTNxPuzKSILRtJ2OzYU7QQ4iy6Pe0 MdUw== 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=VLvm0D1nmVy1ERihwkodjsjVqa9oiCwNeZg629ShJFQ=; b=LVaes0zoKs00SCzWYbYnipK7AAk849VHhtU+HViY25OeyfTbCB6/z+asAOorjG6XKi Zu6d0Cq4HZTVQGzwzirXC/mV0NpYfsTL251sPLJfpP0KDrKnJXAzYAcBlaZ4j6rI/WtT CNFvM8lWbiCFxnfYDem0lhhd6yiMfR8HiLKKyoa0VQ5RiTVoC+ADFNLu+IOgVqGUevOQ O43I3iDTDN/wJIoCfdxvS/9LeTANHNV09WN5E8ye8OWWcw9MZolUvv9IoX87I1Zs/Wo1 arz3FQe+UBHAtsyA04b7hTM3f6vIeelPM3N8Wfjkyh3PUyhfbfTxD4S6kl6PkbKUqLyN hEBA== 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 o61si15149179pld.82.2019.05.26.06.54.12; Sun, 26 May 2019 06:54:27 -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 S1727887AbfEZNvb (ORCPT + 99 others); Sun, 26 May 2019 09:51:31 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:32995 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfEZNva (ORCPT ); Sun, 26 May 2019 09:51:30 -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 relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 56DEF1C000B; Sun, 26 May 2019 13:51:24 +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 v4 03/14] arm64: Consider stack randomization for mmap base only when necessary Date: Sun, 26 May 2019 09:47:35 -0400 Message-Id: <20190526134746.9315-4-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190526134746.9315-1-alex@ghiti.fr> References: <20190526134746.9315-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: Kees Cook Reviewed-by: Christoph Hellwig --- 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