Skip to content

Commit 825ac46

Browse files
committed
ELF: fix kernel.randomize_va_space double read
jira LE-3201 cve CVE-2024-46826 Rebuild_History Non-Buildable kernel-rt-4.18.0-553.27.1.rt7.368.el8_10 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 dde4d70 commit 825ac46

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
@@ -876,7 +876,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
876876
if (elf_read_implies_exec(loc->elf_ex, executable_stack))
877877
current->personality |= READ_IMPLIES_EXEC;
878878

879-
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
879+
const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);
880+
if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space)
880881
current->flags |= PF_RANDOMIZE;
881882

882883
setup_new_exec(bprm);
@@ -1135,7 +1136,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
11351136
current->mm->end_data = end_data;
11361137
current->mm->start_stack = bprm->p;
11371138

1138-
if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) {
1139+
if ((current->flags & PF_RANDOMIZE) && (snapshot_randomize_va_space > 1)) {
11391140
/*
11401141
* For architectures with ELF randomization, when executing
11411142
* a loader directly (i.e. no interpreter listed in ELF

0 commit comments

Comments
 (0)