From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D16B0183CB0; Tue, 10 Sep 2024 09:47:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725961643; cv=none; b=iP7yiRXMjEqObEJJeSHw+6RDIhrYq5yWIMyzlLmjzf77DOTa8T4Gj2xwj2xx9M3fCmQsrx1TUe8U4xYexadh+Q3XWBtlgbuZy9fcTf4ZUPFmKnm1zscfu6FLsJTaXiqf+etiWRBVWyFXuMsZ+M3SZ0LLPyBdS+O0txI5Vzq2+/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725961643; c=relaxed/simple; bh=uQpgVo7RTLr5ry9Gqbgs69JAKFwIAXcrD3ZfRxWL+jU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HcYWiVI538uoXO7BSXVyFBiqYBOXu50z+h78O08cssx+Bn1D2cfXutO4ZL5QxpZhn3+bXc9cYXTulLM+nW0HGzqFAEKXXTfhY3tqYWOV+Q9q8BKVEJlSpoR1kZ4wlnrAuXYT82cQkbI63EAMbT3P8OZqIdgGnFe0b3yFJ8wuMZA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pswU86vK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pswU86vK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57D9EC4CEC3; Tue, 10 Sep 2024 09:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725961643; bh=uQpgVo7RTLr5ry9Gqbgs69JAKFwIAXcrD3ZfRxWL+jU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pswU86vKhGKva0nu3+QvNjQNUc9jhqyplLf1PzES3yilW0waRWo0a+dZyzOGhr366 L2PyX+bt2NPFVNSrPm/sUFh16/TwBuBnODnX6hrgJvrd6b843nV+geHSoMqofAGOVa EkkQjh4YUISzKzU3bT3hofSQk/wUB4pRiqzkCavs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexey Dobriyan , Kees Cook , Sasha Levin Subject: [PATCH 6.10 102/375] ELF: fix kernel.randomize_va_space double read Date: Tue, 10 Sep 2024 11:28:19 +0200 Message-ID: <20240910092625.695301340@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092622.245959861@linuxfoundation.org> References: <20240910092622.245959861@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Dobriyan [ 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 Link: https://lore.kernel.org/r/3329905c-7eb8-400a-8f0a-d87cff979b5b@p183 Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- 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 a43897b03ce9..777405719de8 100644 --- 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 -- 2.43.0