Skip to content
Permalink
Browse files
mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DE…
…FAULT_TOPDOWN_MMAP_LAYOUT

Commit e7142bf ("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 <alex@ghiti.fr>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
  • Loading branch information
chleroy authored and intel-lab-lkp committed Nov 22, 2021
1 parent 1e1147a commit e5949ff1a8e5cae8e9ac2ec3a39849bf2e73eb34
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
@@ -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
@@ -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;
}
@@ -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
@@ -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)
{

0 comments on commit e5949ff

Please sign in to comment.