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 20B5018C02F; Tue, 10 Sep 2024 10:09:02 +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=1725962943; cv=none; b=Kextqvww+ybrn1CeA4JCO9eSIPabg7YWevqUk6ig20gpzhd4k+v4iFTxmmlxpMmHlYFa2rJN1XsZO2uG5/Cse3IKYgw+nZ7AjrggGxYfBkF3K7CA+34JBHqqaxrHwBIt4KbMsfWfbOjfzmBuWgnztX/FBlbyW2+gniMrQA7JNnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962943; c=relaxed/simple; bh=6v/sqXENfCyxxAzpVn/30tb/CP8FcQo7sfEBYkndsHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OohSwTfYlrruB73SXl4s06UlMPr3x9VLlkb0kPbzvPcryf/t4l4MJrApWiARdoCDRDO1PDi0ttTaIjWNsPfo4nCQN/rChEB1hPQqAuAUcTARIgVfWUQV9wHWJ9qbaCcZNsRVGMSfo2U4ZNSMwnn1N7jdPTXycmQmIaDBNOtk0sI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=imisfRa3; 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="imisfRa3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B06DC4CEC3; Tue, 10 Sep 2024 10:09:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725962942; bh=6v/sqXENfCyxxAzpVn/30tb/CP8FcQo7sfEBYkndsHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=imisfRa3g2F5AsktqbBeevFvKDkj7ZzIWV0Eob5zCPBKKPssZa3qdBE74YqL/tV4b myP0EFZ1BPCvwNnaGRd7qRK/chzwX3C8RkyV79PaiGXAONdYzBplEg0xEuGBpRtmaA E3L0sojXoNTvXac4Y4tOZ+wNJU6AnTGKM5SvDp60= 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.1 045/192] ELF: fix kernel.randomize_va_space double read Date: Tue, 10 Sep 2024 11:31:09 +0200 Message-ID: <20240910092559.857086406@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092557.876094467@linuxfoundation.org> References: <20240910092557.876094467@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 e6c9c0e08448..89e7e4826efc 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1009,7 +1009,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); @@ -1301,7 +1302,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