From patchwork Mon Nov 22 08:48:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12631439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47E1DC433F5 for ; Mon, 22 Nov 2021 08:51:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF8896B0075; Mon, 22 Nov 2021 03:49:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECF776B0078; Mon, 22 Nov 2021 03:49:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9A0E6B007B; Mon, 22 Nov 2021 03:49:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id CC89D6B0075 for ; Mon, 22 Nov 2021 03:49:12 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 92D651815B7EC for ; Mon, 22 Nov 2021 08:49:02 +0000 (UTC) X-FDA: 78835941324.22.44ACC15 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf08.hostedemail.com (Postfix) with ESMTP id A4CC030000BD for ; Mon, 22 Nov 2021 08:48:58 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4HyLXh4LfKz9sSk; Mon, 22 Nov 2021 09:48:52 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F-Hpno9y4Il3; Mon, 22 Nov 2021 09:48:52 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4HyLXc0mQLz9sSZ; Mon, 22 Nov 2021 09:48:48 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 025038B77E; Mon, 22 Nov 2021 09:48:48 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 9UYHqUPi79zJ; Mon, 22 Nov 2021 09:48:47 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [172.25.230.108]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9C6258B765; Mon, 22 Nov 2021 09:48:47 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 1AM8meZD631732 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 22 Nov 2021 09:48:40 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 1AM8mecI631731; Mon, 22 Nov 2021 09:48:40 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , alex@ghiti.fr Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Subject: [PATCH 6/8] mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT Date: Mon, 22 Nov 2021 09:48:26 +0100 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1637570906; l=3140; s=20211009; h=from:subject:message-id; bh=AZ109l+llHd6MRuKtoBs1/7LX92fJnFaX5ppcmPYk/k=; b=c1K5qNiDUgf938Fhv0hbNI+x4nVqzA7W5nodpE2TVdar2U38+lhjeUFeWrVU1Yi1kaX+tJephyQT aDVmg4c9ANTiDlaXYDL9TLsmsG3NFa80zhie1WS5xJ91T5Jv/r9q X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A4CC030000BD Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-Stat-Signature: cdkwiw9xcm3ghoesx7qipx6wnhq3hgoq X-HE-Tag: 1637570938-743284 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Commit e7142bf5d231 ("arm64, mm: make randomization selected by generic topdown mmap layout") introduced a default version of arch_randomize_brk() provided when CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT is selected. powerpc could select CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT but needs to provide its own arch_randomize_brk(). In order to allow that, don't make CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select CONFIG_ARCH_HAS_ELF_RANDOMIZE. Instead, ensure that selecting CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT and selecting CONFIG_ARCH_HAS_ELF_RANDOMIZE has the same effect. Then only provide the default arch_randomize_brk() when the architecture has not selected CONFIG_ARCH_HAS_ELF_RANDOMIZE. Cc: Alexandre Ghiti Signed-off-by: Christophe Leroy Reported-by: kernel test robot --- arch/Kconfig | 1 - fs/binfmt_elf.c | 3 ++- include/linux/elf-randomize.h | 3 ++- mm/util.c | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 26b8ed11639d..ef3ce947b7a1 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1000,7 +1000,6 @@ config HAVE_ARCH_COMPAT_MMAP_BASES config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT bool depends on MMU - select ARCH_HAS_ELF_RANDOMIZE config HAVE_STACK_VALIDATION bool diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index f8c7f26f1fbb..28968a189a91 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1287,7 +1287,8 @@ static int load_elf_binary(struct linux_binprm *bprm) * (since it grows up, and may collide early with the stack * growing down), and into the unused ELF_ET_DYN_BASE region. */ - if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) && + if ((IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) || + IS_ENABLED(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)) && elf_ex->e_type == ET_DYN && !interpreter) { mm->brk = mm->start_brk = ELF_ET_DYN_BASE; } diff --git a/include/linux/elf-randomize.h b/include/linux/elf-randomize.h index da0dbb7b6be3..1e471ca7caaf 100644 --- a/include/linux/elf-randomize.h +++ b/include/linux/elf-randomize.h @@ -4,7 +4,8 @@ struct mm_struct; -#ifndef CONFIG_ARCH_HAS_ELF_RANDOMIZE +#if !defined(CONFIG_ARCH_HAS_ELF_RANDOMIZE) && \ + !defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) static inline unsigned long arch_mmap_rnd(void) { return 0; } # if defined(arch_randomize_brk) && defined(CONFIG_COMPAT_BRK) # define compat_brk_randomized diff --git a/mm/util.c b/mm/util.c index e58151a61255..edb9e94cceb5 100644 --- a/mm/util.c +++ b/mm/util.c @@ -344,6 +344,7 @@ unsigned long randomize_stack_top(unsigned long stack_top) } #ifdef CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT +#ifndef CONFIG_ARCH_HAS_ELF_RANDOMIZE unsigned long arch_randomize_brk(struct mm_struct *mm) { /* Is the current task 32bit ? */ @@ -352,6 +353,7 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) return randomize_page(mm->brk, SZ_1G); } +#endif unsigned long arch_mmap_rnd(void) {