From 00c4e9f4d16956ecb2643dcab139b9d6d8962a54 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Fri, 21 Jun 2024 21:54:50 +0300 Subject: [PATCH] ELF: fix kernel.randomize_va_space double read stable inclusion from stable-v6.11-rc1~59^2~3 commit 2a97388a807b6ab5538aa8f8537b2463c6988bd2 category: bugfix issue: #IBCLDP CVE: CVE-2024-46826 Signed-off-by: maxinyi --------------------------------------- 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 Link: https://lore.kernel.org/r/3329905c-7eb8-400a-8f0a-d87cff979b5b@p183 Signed-off-by: Kees Cook Signed-off-by: mxy Conflicts: fs/binfmt_elf.c --- fs/binfmt_elf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 2321cf51f48e..f949d4832dc4 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -839,6 +839,7 @@ static int load_elf_binary(struct linux_binprm *bprm) struct arch_elf_state arch_state = INIT_ARCH_ELF_STATE; struct mm_struct *mm; struct pt_regs *regs; + const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space); retval = -ENOEXEC; /* First of all, some simple consistency checks */ @@ -1005,7 +1006,7 @@ static int load_elf_binary(struct linux_binprm *bprm) if (elf_read_implies_exec(*elf_ex, executable_stack)) current->personality |= READ_IMPLIES_EXEC; - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) + if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space) current->flags |= PF_RANDOMIZE; setup_new_exec(bprm); @@ -1299,7 +1300,7 @@ static int load_elf_binary(struct linux_binprm *bprm) mm->end_data = end_data; mm->start_stack = bprm->p; - if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) { + if ((current->flags & PF_RANDOMIZE) && (snapshot_randomize_va_space > 1)) { /* * For architectures with ELF randomization, when executing * a loader directly (i.e. no interpreter listed in ELF -- Gitee