* [PATCH AUTOSEL 4.19 06/14] ELF: fix kernel.randomize_va_space double read
[not found] <20240801004037.3939932-1-sashal@kernel.org>
@ 2024-08-01 0:40 ` Sasha Levin
2024-08-27 12:18 ` Pavel Machek
0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2024-08-01 0:40 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Alexey Dobriyan, Kees Cook, Sasha Levin, viro, brauner,
linux-fsdevel, linux-mm
From: Alexey Dobriyan <adobriyan@gmail.com>
[ Upstream commit 2a97388a807b6ab5538aa8f8537b2463c6988bd2 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 c41c568ad1b8a..af8830878fa0b 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -876,7 +876,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
if (elf_read_implies_exec(loc->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);
@@ -1136,7 +1137,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
current->mm->end_data = end_data;
current->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
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH AUTOSEL 4.19 06/14] ELF: fix kernel.randomize_va_space double read
2024-08-01 0:40 ` [PATCH AUTOSEL 4.19 06/14] ELF: fix kernel.randomize_va_space double read Sasha Levin
@ 2024-08-27 12:18 ` Pavel Machek
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2024-08-27 12:18 UTC (permalink / raw)
To: Sasha Levin
Cc: linux-kernel, stable, Alexey Dobriyan, Kees Cook, viro, brauner,
linux-fsdevel, linux-mm
[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]
Hi!
> [ Upstream commit 2a97388a807b6ab5538aa8f8537b2463c6988bd2 ]
>
> 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>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> 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 c41c568ad1b8a..af8830878fa0b 100644
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -876,7 +876,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
> if (elf_read_implies_exec(loc->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);
We normally put variable declaration at start of the function. I'd not
be surprised if this broke with older compilers.
Best regards,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-27 12:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240801004037.3939932-1-sashal@kernel.org>
2024-08-01 0:40 ` [PATCH AUTOSEL 4.19 06/14] ELF: fix kernel.randomize_va_space double read Sasha Levin
2024-08-27 12:18 ` Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).