Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2735087ybi; Sun, 26 May 2019 06:55:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsp/38AtirnvdVzkiQUV4qbAgeCJph+iAPO3YY9LNgO6V0jPlJUVjO5ImJfu+Tax/naGet X-Received: by 2002:a62:7689:: with SMTP id r131mr128430591pfc.181.1558878910682; Sun, 26 May 2019 06:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558878910; cv=none; d=google.com; s=arc-20160816; b=X061ZKb8Yv8njxbg9rB47SyUk9WXEzrOK2X3E383xx9WmDXkhibWvYzG6/HZvA8N7x itUreuAj4zCL6rbTV8aWd0alg7D5G2FXEPCXjf+UWlXo7uBLHVLZJb5raA75vU+9j15k 3VOL2fSsK7TzQrlxEpHs+tzWyN0Qf6tfEfShggwP8DBN5pGYaBTAfuYS7z3uPG0wH2mV CDYKWrOz97HayMYjZb4PAgVxw7GEwH95cVtIbkPH8lHPK741s1uMt8peZzu4Vip3eYMQ fjWuk+JdiTfNKiVB0CK3No2hTqWZqRR/4bMAbpaR6lZVMd06p27fDiUzcUsdHYG2CHqi wX2g== 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=VTQC7kI6uLCH8Kj/P0fJoMTcPRoRnmnCtakF65iLIOc=; b=s01mm7sPQmYRPPQ5CKpT3d0sq95/3Cr6c880/X/H10jH8Vkt9LNfehVn1YY879VPHS YONqEc20nAxFRu/TnyvpyxBdD+tA4cN1FjmRCYf1Jmem/higiTXO/rPfh5lo9HOuZVjn zlibEwEG2+dQldkM/0v2OKzsS8CDDA60PhUl0UQTAVABIX8KoFBRBzpsUMQCQfL6FISM 8dAPQQQ8ofKgC2x6l0mATNVLnRo28cRux+yiv1gyxRA6xwiOEH46DUhl/8hYvAUQz8zl 5adzgplToeo/v6ugTzbnqmdFRUB+turk8RFUYQrLaipe3zxw+hbaIQH3UEh+5WFrObJ8 +fyg== 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 v13si13357808plo.429.2019.05.26.06.54.55; Sun, 26 May 2019 06:55:10 -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 S1727829AbfEZNxv (ORCPT + 99 others); Sun, 26 May 2019 09:53:51 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:60931 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfEZNxv (ORCPT ); Sun, 26 May 2019 09:53:51 -0400 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay11.mail.gandi.net (Postfix) with ESMTPSA id EAC53100002; Sun, 26 May 2019 13:53:41 +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 05/14] arm64, mm: Make randomization selected by generic topdown mmap layout Date: Sun, 26 May 2019 09:47:37 -0400 Message-Id: <20190526134746.9315-6-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 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 --- 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 df3ab04270fa..3732654446cc 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -710,6 +710,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 3d754c19c11e..403bd3fffdbc 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -15,7 +15,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 3767fb21a5b8..3f85f8f2d665 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -535,14 +535,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 717f5d75c16e..8a38126edc74 100644 --- a/mm/util.c +++ b/mm/util.c @@ -319,7 +319,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; @@ -333,7 +341,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