Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6417434ybh; Wed, 7 Aug 2019 23:42:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzK+uhOd/TyUjKrxUZ0bLQ79tvV8HQhnpkMJKlFL+QWH5fcYFnCgDxYUccBFzwTU6cquTlN X-Received: by 2002:a62:f202:: with SMTP id m2mr14201646pfh.6.1565246567510; Wed, 07 Aug 2019 23:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565246567; cv=none; d=google.com; s=arc-20160816; b=BJaawhMulZFnaMnFP0X2PafUwtyHAUAF6vdVNur0MLxtLxzWs9c3izqnIFtS32/B9K QEEnjHjLGdGu3X2CfwLhPyowWaztr3HzYBxWJRtB301MZsR34gvDG4dB0ZzgmR99gdJo p/FEMr7Ll3nVdk7XjCM9RCPh8XCvGJ1HPz+Uif2zn0GzqmHSfqK9Jrf+FuFDXifskb86 l80HhGmUWm4UFempz7poISLkFZyE60l1OJW5ZQAzSHNK/T4zOW+J5A9LpB1kJoMIzF0f wiSgbvJGtj2pAZ7xJsZwARTPajoQAjrsVWUsucfCXo3W0tpa6U4M9bKSUkFppvwKoHF3 9kXw== 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=AjDywMADdqbjYLt4JKIFDlp+tRhq/P4Zgz2k8rU647tmDuZQWnsmWria9w8JJD/LTS QQKa1UDh83S+EMZ3jLy9fstNN31C4vkmdOmbuYKs8AYEZvXKvbN9eENBp/ErxPSI+0vH 6rPyadV1Zl7v8ghH0eRKBXUQKs04XhwmacKhbB6A4NgGmcYwt/KVzZxnY5bNKCK4RyzV IrsWZP9zVoXrZPm38uWXjIra3T7PRQvtRPGzk05k0yJQWcKBm+1suNg012iPonatKhDM sG7Ru0xqexwO/soNLi/uT9tddfPaG2LigmPjuO+EfXiOMhhgtBx8R15soZwQ8vntUIBF BUDQ== 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 b18si53231759pgl.52.2019.08.07.23.42.32; Wed, 07 Aug 2019 23:42:47 -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 S1731186AbfHHGV3 (ORCPT + 99 others); Thu, 8 Aug 2019 02:21:29 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:52355 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731005AbfHHGV1 (ORCPT ); Thu, 8 Aug 2019 02:21:27 -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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 1AE39E0004; Thu, 8 Aug 2019 06:21:18 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Paul Walmsley , 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 v6 03/14] arm64: Consider stack randomization for mmap base only when necessary Date: Thu, 8 Aug 2019 02:17:45 -0400 Message-Id: <20190808061756.19712-4-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808061756.19712-1-alex@ghiti.fr> References: <20190808061756.19712-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