From nobody Tue Dec 16 16:41:13 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33C2DC4167B for ; Fri, 8 Dec 2023 18:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574600AbjLHSN1 (ORCPT ); Fri, 8 Dec 2023 13:13:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235941AbjLHSNC (ORCPT ); Fri, 8 Dec 2023 13:13:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C555B199B; Fri, 8 Dec 2023 10:13:05 -0800 (PST) Date: Fri, 08 Dec 2023 18:13:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702059184; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mRgMpEtOSJBHDWGivEkUzrK1mBwzcnA7ULdr1D3O8kk=; b=GRKKFx0OhwyKZC8SiqPEB21TfTXQe066OGHnGnkm5FN0JVCm2+uSToyjKl3XBU3buzDGD2 73GGP9h+yAtGpD/sktTFX7CDH33eQAZUx1iMXHILO8t4p1Q/WnEo5BmYOvvk+2zzM9eBz7 fQWERD/e2x08m1q5wvPVyos2vd6LkVBJ7lEh2gce2l30f5TWYxFq6Wniqw+rZQ+zeX09rs LWYQRdRkMoJP0QBCqmPT4NGlV65XAA6nGaO8ASZpmIUhTRtdRY+xOG6cB7ZXf8xFM9wFLy 8o+acu5AHi1TlWkRkTihQm07h1D9436ZuuUT8HkX6vzD7Ym0VzxSAJbSk76B3g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702059184; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mRgMpEtOSJBHDWGivEkUzrK1mBwzcnA7ULdr1D3O8kk=; b=7GCNvhFWlJ2j4apzg+PtMg3sa6R9HAcjSIl1BQ98xe66xmQ7VBozQTyiSYuBuug1NozCug 23WC4LRRg+yS4NDA== From: "tip-bot2 for Jo Van Bulck" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sgx] selftests/sgx: Fix uninitialized pointer dereferences in encl_get_entry Cc: Jo Van Bulck , Dave Hansen , Jarkko Sakkinen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <170205918374.398.6959285189365623759.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/sgx branch of tip: Commit-ID: b84fc2e0139ba4b23b8039bd7cfd242894fe8f8b Gitweb: https://git.kernel.org/tip/b84fc2e0139ba4b23b8039bd7cfd24289= 4fe8f8b Author: Jo Van Bulck AuthorDate: Thu, 05 Oct 2023 17:38:43 +02:00 Committer: Dave Hansen CommitterDate: Fri, 08 Dec 2023 10:05:26 -08:00 selftests/sgx: Fix uninitialized pointer dereferences in encl_get_entry Ensure sym_tab and sym_names are zero-initialized and add an early-out condition in the unlikely (erroneous) case that the enclave ELF file would not contain a symbol table. This addresses -Werror=3Dmaybe-uninitialized compiler warnings for gcc -O2. Fixes: 33c5aac3bf32 ("selftests/sgx: Test complete changing of page type fl= ow") Signed-off-by: Jo Van Bulck Signed-off-by: Dave Hansen Reviewed-by: Jarkko Sakkinen Link: https://lore.kernel.org/all/20231005153854.25566-3-jo.vanbulck%40cs.k= uleuven.be --- tools/testing/selftests/sgx/load.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/sgx/load.c b/tools/testing/selftests/s= gx/load.c index 94bdeac..c9f658e 100644 --- a/tools/testing/selftests/sgx/load.c +++ b/tools/testing/selftests/sgx/load.c @@ -136,11 +136,11 @@ static bool encl_ioc_add_pages(struct encl *encl, str= uct encl_segment *seg) */ uint64_t encl_get_entry(struct encl *encl, const char *symbol) { + Elf64_Sym *symtab =3D NULL; + char *sym_names =3D NULL; Elf64_Shdr *sections; - Elf64_Sym *symtab; Elf64_Ehdr *ehdr; - char *sym_names; - int num_sym; + int num_sym =3D 0; int i; =20 ehdr =3D encl->bin; @@ -161,6 +161,9 @@ uint64_t encl_get_entry(struct encl *encl, const char *= symbol) } } =20 + if (!symtab || !sym_names) + return 0; + for (i =3D 0; i < num_sym; i++) { Elf64_Sym *sym =3D &symtab[i];