Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 2a97388

Browse files
Alexey Dobriyankees
authored andcommitted
ELF: fix kernel.randomize_va_space double read
ELF loader uses "randomize_va_space" twice. It is sysctl and can change at any moment, so 2 loads could see 2 different values in theory with unpredictable consequences. Issue exactly one load for consistent value across one exec. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Link: https://lore.kernel.org/r/3329905c-7eb8-400a-8f0a-d87cff979b5b@p183 Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 60371f4 commit 2a97388

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/binfmt_elf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
10031003
if (elf_read_implies_exec(*elf_ex, executable_stack))
10041004
current->personality |= READ_IMPLIES_EXEC;
10051005

1006-
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1006+
const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);
1007+
if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space)
10071008
current->flags |= PF_RANDOMIZE;
10081009

10091010
setup_new_exec(bprm);
@@ -1285,7 +1286,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
12851286
mm->end_data = end_data;
12861287
mm->start_stack = bprm->p;
12871288

1288-
if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) {
1289+
if ((current->flags & PF_RANDOMIZE) && (snapshot_randomize_va_space > 1)) {
12891290
/*
12901291
* For architectures with ELF randomization, when executing
12911292
* a loader directly (i.e. no interpreter listed in ELF

0 commit comments

Comments
 (0)