* [PATCH] ELF: fix kernel.randomize_va_space double read
@ 2024-06-21 18:54 Alexey Dobriyan
2024-06-21 19:40 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Dobriyan @ 2024-06-21 18:54 UTC (permalink / raw)
To: Eric Biederman, Kees Cook; +Cc: linux-kernel, linux-mm, akpm
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>
---
fs/binfmt_elf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1003,7 +1003,8 @@ 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)
+ const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space);
+ if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space)
current->flags |= PF_RANDOMIZE;
setup_new_exec(bprm);
@@ -1251,7 +1252,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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ELF: fix kernel.randomize_va_space double read
2024-06-21 18:54 [PATCH] ELF: fix kernel.randomize_va_space double read Alexey Dobriyan
@ 2024-06-21 19:40 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2024-06-21 19:40 UTC (permalink / raw)
To: Eric Biederman, Alexey Dobriyan; +Cc: Kees Cook, linux-kernel, linux-mm, akpm
On Fri, 21 Jun 2024 21:54:50 +0300, Alexey Dobriyan wrote:
> 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.
>
>
> [...]
Applied to for-next/execve, thanks!
[1/1] ELF: fix kernel.randomize_va_space double read
https://git.kernel.org/kees/c/2a97388a807b
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-21 19:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-21 18:54 [PATCH] ELF: fix kernel.randomize_va_space double read Alexey Dobriyan
2024-06-21 19:40 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox