From patchwork Fri Dec 8 18:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 175993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5632177vqy; Fri, 8 Dec 2023 10:13:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqSSPneUVpXMFJLw14X9z2SjdguaC89GXZY/ZYxYHCh3EiFZ/uZG8PyujlNiIMcXQBVe/R X-Received: by 2002:a05:6a20:ceaf:b0:18f:97c:9276 with SMTP id if47-20020a056a20ceaf00b0018f097c9276mr378625pzb.91.1702059218991; Fri, 08 Dec 2023 10:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702059218; cv=none; d=google.com; s=arc-20160816; b=pH5E+iDMX1COM8iXCdScG3nm884+T0rKr88DNPT99kL7Hkp+mOU45F/akqkiRiB2r7 vQJaC4jdzFDXkWOqvR/r8bhwMXLKoP/1N0aqFWEs07gs5Fuja941guJmKqC7kI5sAAWk U5OC6SmY+9oZ7onttyhEoawerjMnKLsCEwAbU7qcJW88sbKkVfvkwOlO8ZKFOlridDIH tWGLTc984076LZvC85w0oxZmOeZjpakeC/ej+NjDEBQ6xiR1EGaheq/ZZIrGVRPFNPGm ePpDAITM9Y+FZl+dEWv4tUscHqBwNE4dWuv8L6UQow60QXPbxV/2BXxbuRzDP8bP6EvC kIqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=mRgMpEtOSJBHDWGivEkUzrK1mBwzcnA7ULdr1D3O8kk=; fh=/n9XlXj1IKUyPlyHECKcBKWdQ7usrdaKCfKX5noQGgg=; b=FgaVhZsqyyihyORhDQj5vSQ7qm1Ci3QnJhMqnY5j1JHuFrzKwSTKFOMPxfGjBFGyre pB0vJ4tqAP9jzqL83HzUXDvgBupzSrkH23+i7rglI2rPQJxB+EmEn0MzbvDHm6sfFp9g gMwtikaYSMun32gL6ihjwLwWdBtKmhDZfWL+sZ2/KBBsvrWpS5W9fWgjp3zk4J8c418w sK2/eLVThXztW0ALqvHf3uWo0wqrjDSWWGpBIcDJ438VrcgLPKLgbgWKlSDhXJCMf/UG 8Gy4nqat5VMCKroFnz3tp37gTsuPpptAyi9lqp3HnXy/Hn+R9ooXbKP+vWmwTo1hm7DI Lacw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GRKKFx0O; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cp21-20020a056a00349500b006ce56664fd5si1882702pfb.157.2023.12.08.10.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 10:13:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GRKKFx0O; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0533481043B7; Fri, 8 Dec 2023 10:13:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236014AbjLHSNZ (ORCPT + 99 others); Fri, 8 Dec 2023 13:13:25 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 08 Dec 2023 10:13:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784738447591843977 X-GMAIL-MSGID: 1784738447591843977 The following commit has been merged into the x86/sgx branch of tip: Commit-ID: b84fc2e0139ba4b23b8039bd7cfd242894fe8f8b Gitweb: https://git.kernel.org/tip/b84fc2e0139ba4b23b8039bd7cfd242894fe8f8b 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=maybe-uninitialized compiler warnings for gcc -O2. Fixes: 33c5aac3bf32 ("selftests/sgx: Test complete changing of page type flow") 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.kuleuven.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/sgx/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, struct encl_segment *seg) */ uint64_t encl_get_entry(struct encl *encl, const char *symbol) { + Elf64_Sym *symtab = NULL; + char *sym_names = NULL; Elf64_Shdr *sections; - Elf64_Sym *symtab; Elf64_Ehdr *ehdr; - char *sym_names; - int num_sym; + int num_sym = 0; int i; ehdr = encl->bin; @@ -161,6 +161,9 @@ uint64_t encl_get_entry(struct encl *encl, const char *symbol) } } + if (!symtab || !sym_names) + return 0; + for (i = 0; i < num_sym; i++) { Elf64_Sym *sym = &symtab[i];