Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6418908ybh; Wed, 7 Aug 2019 23:44:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfI5Y4FXwF5zY/bpIUWkSWi2PA2gPGtObpFGm7ofF1Hsa3N8H/0mLlCsUp2yC8J+bAEnJk X-Received: by 2002:a63:de4f:: with SMTP id y15mr11670736pgi.239.1565246670779; Wed, 07 Aug 2019 23:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565246670; cv=none; d=google.com; s=arc-20160816; b=04tT8g3DJsniKugiodGyalgoEnN/N1qYX21hMaSTKnI6xKkOao62EV52Fvtr2TVyxQ lEiUpX+bqYjxxfQ/7RidilB4rTW444by4GhQ1bvfTiQEwPomyekLIPPUixZ2HMwGe7uc G1alGfC7OLVSnl7FSljw+6CGhD0GPcZ3nJ/I2ByQlzsa0+9FG/poYmlKVydFQWL5N3hI spDyepKmekEiJD1h0s97UZoNh7vbjMT8Vd9TqPGZCyD1H81FAIiQuEZjsQr7+bIhujr+ PQY6KXjOMW1lE+1Zk+udAV3+NFHlPduM6MZfgfSmGhIiWpdxAAiCeQyp8Obq/K9g4l/3 enEw== 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=Uc9HCc/6hNvOV8B2vZv1Mz7T1SIEtuaecktNCSj6hGE=; b=QL433TjWTNWu2Ejq0iF2BSeT8kwg+8xh2YcmJDq0H3aEBEl75QOtAaUjFROmBezmwq VguugU5IhL7o3/nEnP6fYIwtfEqzc58pcO3QbAwODZVJnff4/kLcNTomsvsZ/DagyLj4 0FuzY23GmwUrlS2DrAoz33DeAy5oXPJCWVvszd65hO2F//xszfWCHB9FH98GY6gv96ee R4T6Q1qJnJQb59r07AK574BrF2S2ZxNFQy932406JzROVkj4PEZPBX1NANOYAOg4g+zt o6nPaZosqp+P5Fk9OQlJtXLfdsyGcnRlvx9eE7DcSXFrTPaqOQkVw0bbr3n6HGyOoZFz RTpQ== 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 g3si53921804pgo.241.2019.08.07.23.44.15; Wed, 07 Aug 2019 23:44:30 -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 S1731162AbfHHGXh (ORCPT + 99 others); Thu, 8 Aug 2019 02:23:37 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:45907 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730626AbfHHGXh (ORCPT ); Thu, 8 Aug 2019 02:23:37 -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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id D423E60002; Thu, 8 Aug 2019 06:23:30 +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 05/14] arm64, mm: Make randomization selected by generic topdown mmap layout Date: Thu, 8 Aug 2019 02:17:47 -0400 Message-Id: <20190808061756.19712-6-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 This commits selects ARCH_HAS_ELF_RANDOMIZE when an arch uses the generic topdown mmap layout functions so that this security feature is on by default. Note that this commit also removes the possibility for arm64 to have elf randomization and no MMU: without MMU, the security added by randomization is worth nothing. Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- arch/Kconfig | 1 + arch/arm64/Kconfig | 1 - arch/arm64/kernel/process.c | 8 -------- mm/util.c | 11 +++++++++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index a0bb6fa4d381..d4c1f0551dfe 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -705,6 +705,7 @@ config HAVE_ARCH_COMPAT_MMAP_BASES config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT bool depends on MMU + select ARCH_HAS_ELF_RANDOMIZE config HAVE_COPY_THREAD_TLS bool diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 14a194e63458..399f595ef852 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -16,7 +16,6 @@ config ARM64 select ARCH_HAS_DMA_MMAP_PGPROT select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI - select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index f674f28df663..8ddc2471b054 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -548,14 +548,6 @@ unsigned long arch_align_stack(unsigned long sp) return sp & ~0xf; } -unsigned long arch_randomize_brk(struct mm_struct *mm) -{ - if (is_compat_task()) - return randomize_page(mm->brk, SZ_32M); - else - return randomize_page(mm->brk, SZ_1G); -} - /* * Called from setup_new_exec() after (COMPAT_)SET_PERSONALITY. */ diff --git a/mm/util.c b/mm/util.c index 0781e5575cb3..16f1e56e2996 100644 --- a/mm/util.c +++ b/mm/util.c @@ -321,7 +321,15 @@ unsigned long randomize_stack_top(unsigned long stack_top) } #ifdef CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT -#ifdef CONFIG_ARCH_HAS_ELF_RANDOMIZE +unsigned long arch_randomize_brk(struct mm_struct *mm) +{ + /* Is the current task 32bit ? */ + if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task()) + return randomize_page(mm->brk, SZ_32M); + + return randomize_page(mm->brk, SZ_1G); +} + unsigned long arch_mmap_rnd(void) { unsigned long rnd; @@ -335,7 +343,6 @@ unsigned long arch_mmap_rnd(void) return rnd << PAGE_SHIFT; } -#endif /* CONFIG_ARCH_HAS_ELF_RANDOMIZE */ static int mmap_is_legacy(struct rlimit *rlim_stack) { -- 2.20.1