Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9160275ybi; Tue, 23 Jul 2019 23:03:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJfMNXsWScM18Fovq9Z5P3LMfkqt6Sh+VGioWKtXlUA+WkyyNmbSjG0nItZ0JANniicN/j X-Received: by 2002:aa7:8804:: with SMTP id c4mr9498438pfo.65.1563948201952; Tue, 23 Jul 2019 23:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948201; cv=none; d=google.com; s=arc-20160816; b=RCxpI28u8hThj0lRdVx1n9Iu7tjDxSP3fslesU8NHeOQY75VCv09IbsRCk3TYRbj2X OkWfmSv0HKn93AGvEFKDAUMPwbHcGBYUv007T5fOprYMOOuNYnFiReZhhUk0VAAVg7YU wsosYZPs9UEbwHbOgceIHYuOufKT4o553YZ+KzgosMaebP5oEnxJIBun5+mj906VkYdz i7krnRx0H6TOeFEkjq7+36tLj1sno+MZ5fOCnrTxislS9lnBtaeE1K+9J1UcCqyZHxJA da18CCdYti2rwcAcG8opudMf1zVH6h8vc86c/AVOn4K5smhcbrghC5JjHVNZ7RaXrrEe GJ9g== 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=KhEHOzJH1XekHaEjlNvFqkjJE/BSWfvZ32hlPcMINEc=; b=TWLfJNcI5AllEMGEdnpq3ZhPDmGrueYs8cLprShLJiMF1RVXmBmJWicOR9Uu+2OITt ubXW+qP+dS26ikOAFtEdJU5EY3xWnqN1KEoa/Aewnw9A5seYPYJ7cb68GEK0AztN3HEq T657+M9mM54wPeNNX+koUQC0NvojqQ7nv14NkrAAsyZwi8ji9vkfD6Y7uiy6AY4kI7/T EjRVx8LVnC896GqaOd18jwm9gMnlScecmciDRIwjyvNJPPdU9rquSYbIB9WMNrqzeypD 3YS+lDJ+LLIMSxLEDQmKjkXwDmmGCFZyR3TT6XqQhw0sHA+FlsqbKNVbBos/Laojs5cw 27xg== 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 u16si17330078pjb.15.2019.07.23.23.03.07; Tue, 23 Jul 2019 23:03:21 -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 S1726283AbfGXGCV (ORCPT + 99 others); Wed, 24 Jul 2019 02:02:21 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:42487 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbfGXGCV (ORCPT ); Wed, 24 Jul 2019 02:02:21 -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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id AF3E124000A; Wed, 24 Jul 2019 06:02:15 +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 03/14] arm64: Consider stack randomization for mmap base only when necessary Date: Wed, 24 Jul 2019 01:58:39 -0400 Message-Id: <20190724055850.6232-4-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 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 --- 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