From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
Kees Cook <kees@kernel.org>, Sasha Levin <sashal@kernel.org>,
viro@zeniv.linux.org.uk, brauner@kernel.org,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH AUTOSEL 5.4 12/22] ELF: fix kernel.randomize_va_space double read
Date: Wed, 31 Jul 2024 20:38:41 -0400 [thread overview]
Message-ID: <20240801003918.3939431-12-sashal@kernel.org> (raw)
In-Reply-To: <20240801003918.3939431-1-sashal@kernel.org>
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 72cd871544ac0..33c323a2ccb19 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -854,7 +854,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);
@@ -1106,7 +1107,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
next prev parent reply other threads:[~2024-08-01 0:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 0:38 [PATCH AUTOSEL 5.4 01/22] drm/amdgpu: fix overflowed array index read warning Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 02/22] drm/amd/display: Check gpio_id before used as array index Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 03/22] drm/amd/display: Stop amdgpu_dm initialize when stream nums greater than 6 Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 04/22] drm/amd/display: Check num_valid_sets before accessing reader_wm_sets[] Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 05/22] drm/amd/display: Fix Coverity INTEGER_OVERFLOW within dal_gpio_service_create Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 06/22] drm/amdgpu: fix ucode out-of-bounds read warning Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 07/22] drm/amdgpu: fix mc_data " Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 08/22] drm/amdkfd: Reconcile the definition and use of oem_id in struct kfd_topology_device Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 09/22] smack: tcp: ipv4, fix incorrect labeling Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 10/22] wifi: cfg80211: make hash table duplicates more survivable Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 11/22] drm/amd/display: Skip wbscl_set_scaler_filter if filter is null Sasha Levin
2024-08-01 0:38 ` Sasha Levin [this message]
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 13/22] udf: Avoid excessive partition lengths Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 14/22] usb: uas: set host status byte on data completion error Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 15/22] cgroup: Protect css->cgroup write under css_set_lock Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 16/22] um: line: always fill *error_out in setup_one_line() Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 17/22] devres: Initialize an uninitialized struct member Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 18/22] pci/hotplug/pnv_php: Fix hotplug driver crash on Powernv Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 19/22] hwmon: (lm95234) Fix underflows seen when writing limit attributes Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 20/22] hwmon: (w83627ehf) " Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 21/22] libbpf: Add NULL checks to bpf_object__{prev_map,next_map} Sasha Levin
2024-08-01 0:38 ` [PATCH AUTOSEL 5.4 22/22] wifi: mwifiex: Do not return unused priv in mwifiex_get_priv_by_id() Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240801003918.3939431-12-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=adobriyan@gmail.com \
--cc=brauner@kernel.org \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox