LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Alex Ghiti <alex@ghiti.fr>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Michael Ellerman <mpe@ellerman.id.au>
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-mm@kvack.org
Subject: Re: [PATCH 6/8] mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
Date: Mon, 22 Nov 2021 12:22:46 +0100 [thread overview]
Message-ID: <325663a5-d9a1-a8b8-7f16-c2985c319864@ghiti.fr> (raw)
In-Reply-To: <e2209d0f1f3c1b581592bd6c32243402ccfe3dde.1637570556.git.christophe.leroy@csgroup.eu>
Hi Christophe,
Le 22/11/2021 à 09:48, Christophe Leroy a écrit :
> 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.
This feels weird to me since if CONFIG_ARCH_HAS_ELF_RANDOMIZE is used
somewhere else at some point, it is not natural to add
CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT: can't we use a __weak
function or a new CONFIG_ARCH_HAS_RANDOMIZE_BRK?
Thanks,
Alex
>
> Then only provide the default arch_randomize_brk() when the
> architecture has not selected CONFIG_ARCH_HAS_ELF_RANDOMIZE.
>
> Cc: Alexandre Ghiti <alex@ghiti.fr>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> 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)
> {
>
next prev parent reply other threads:[~2021-11-22 11:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 8:48 [PATCH 0/8] Convert powerpc to default topdown mmap layout Christophe Leroy
2021-11-22 8:48 ` [PATCH 1/8] powerpc/mm: Make slice specific to book3s/64 Christophe Leroy
2021-11-22 14:48 ` kernel test robot
2021-11-24 12:10 ` Christophe Leroy
2021-11-24 13:49 ` Christophe Leroy
2021-11-26 5:15 ` [kbuild-all] " Chen, Rong A
2021-11-22 21:10 ` kernel test robot
2021-11-24 12:10 ` Christophe Leroy
2021-11-22 8:48 ` [PATCH 2/8] powerpc/mm: Remove CONFIG_PPC_MM_SLICES Christophe Leroy
2021-11-22 8:48 ` [PATCH 3/8] powerpc/mm: Remove asm/slice.h Christophe Leroy
2021-11-22 8:48 ` [PATCH 4/8] powerpc/mm: Move vma_mmu_pagesize() and hugetlb_get_unmapped_area() to slice.c Christophe Leroy
2021-11-22 8:48 ` [PATCH 5/8] powerpc/mm: Call radix__arch_get_unmapped_area() from arch_get_unmapped_area() Christophe Leroy
2021-11-22 8:48 ` [PATCH 6/8] mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT Christophe Leroy
2021-11-22 11:22 ` Alex Ghiti [this message]
2021-11-22 11:47 ` Christophe Leroy
2021-11-22 12:57 ` Alexandre ghiti
2021-11-23 0:22 ` kernel test robot
2021-11-22 8:48 ` [PATCH 7/8] powerpc/mm: Convert to default topdown mmap layout Christophe Leroy
2021-11-22 8:48 ` [PATCH 8/8] powerpc/mm: Properly randomise mmap with slices Christophe Leroy
2021-11-24 13:21 ` [PATCH 0/8] Convert powerpc to default topdown mmap layout Nicholas Piggin
2021-11-24 13:40 ` Christophe Leroy
2021-11-24 18:00 ` Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=325663a5-d9a1-a8b8-7f16-c2985c319864@ghiti.fr \
--to=alex@ghiti.fr \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@csgroup.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--subject='Re: [PATCH 6/8] mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).