Skip to content

Commit 97975ab

Browse files
committed
ELF: fix kernel.randomize_va_space double read
jira LE-2974 cve CVE-2024-46826 Rebuild_History Non-Buildable kernel-5.14.0-503.40.1.el9_5 commit-author Alexey Dobriyan <adobriyan@gmail.com> commit 2a97388 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> (cherry picked from commit 2a97388) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent a21ad3a commit 97975ab

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
@@ -1008,7 +1008,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
10081008
if (elf_read_implies_exec(*elf_ex, executable_stack))
10091009
current->personality |= READ_IMPLIES_EXEC;
10101010

1011-
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1011+
const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);
1012+
if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space)
10121013
current->flags |= PF_RANDOMIZE;
10131014

10141015
setup_new_exec(bprm);
@@ -1266,7 +1267,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
12661267
mm->end_data = end_data;
12671268
mm->start_stack = bprm->p;
12681269

1269-
if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) {
1270+
if ((current->flags & PF_RANDOMIZE) && (snapshot_randomize_va_space > 1)) {
12701271
/*
12711272
* For architectures with ELF randomization, when executing
12721273
* a loader directly (i.e. no interpreter listed in ELF

0 commit comments

Comments
 (0)