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 D906F58116; Tue, 23 Jan 2024 00:32:00 +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=1705969920; cv=none; b=Yj6C2HnfBU142WoVGXaQxsCXWo8hTX59WGrdwFjBGIUs4twa+e42C5Ydj4+j+PLacsN/Cu+Aw/1Tz3XpCkEN2INdg7GC6FYIEXRUKJZFdA6zEsqYT33uNf6HcR88P72HjbN9v93jE0J2RwP4GWJYESKbR/qZAJAwzxxILMvUZwA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969920; c=relaxed/simple; bh=qAkZApl6ymsEpdw0CXnfNoQs0wWMT9u74o01kO8k2ao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Luw/I2gg944MBKYWbyp5X9u6nn0zCTx3FVVfAbIqnuIGMe7+uou4iTPJyl3GL6tGMoqbLaJj2/ehmTPVwM+nZCU4rs2Q93uM3mdmCdCBPKGSPgFTzJ3YSPjX48L2XZHxuhJx9bEwO+zURPQ1u0Dy8JICRc0DTh5BADr904H/W10= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vQoE+uGp; 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="vQoE+uGp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C187C433F1; Tue, 23 Jan 2024 00:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969920; bh=qAkZApl6ymsEpdw0CXnfNoQs0wWMT9u74o01kO8k2ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQoE+uGpFc+Sc9bYA+4WDWoGh7hOZoaRG9n9asYbhgfaY8sTVIDMhxTRVQAxgO2WQ BbZARGlgfykFBfEZAN2fzDQWhc+Dik2eo1kMoPvCPuEpEFx0jn5bYx+P6qhJ+6ydTr Y7WPW5TNiwV3XosBtH2wLhpatCaaiqld132fnsuw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jo Van Bulck , Dave Hansen , Jarkko Sakkinen , Kai Huang , Sasha Levin Subject: [PATCH 6.7 524/641] selftests/sgx: Fix uninitialized pointer dereference in error path Date: Mon, 22 Jan 2024 15:57:08 -0800 Message-ID: <20240122235834.485796945@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235818.091081209@linuxfoundation.org> References: <20240122235818.091081209@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.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jo Van Bulck [ Upstream commit 79eba8c924f7decfa71ddf187d38cb9f5f2cd7b3 ] Ensure ctx is zero-initialized, such that the encl_measure function will not call EVP_MD_CTX_destroy with an uninitialized ctx pointer in case of an early error during key generation. Fixes: 2adcba79e69d ("selftests/x86: Add a selftest for SGX") Signed-off-by: Jo Van Bulck Signed-off-by: Dave Hansen Reviewed-by: Jarkko Sakkinen Acked-by: Kai Huang Link: https://lore.kernel.org/all/20231005153854.25566-2-jo.vanbulck%40cs.kuleuven.be Signed-off-by: Sasha Levin --- tools/testing/selftests/sgx/sigstruct.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/sgx/sigstruct.c b/tools/testing/selftests/sgx/sigstruct.c index a07896a46364..d73b29becf5b 100644 --- a/tools/testing/selftests/sgx/sigstruct.c +++ b/tools/testing/selftests/sgx/sigstruct.c @@ -318,9 +318,9 @@ bool encl_measure(struct encl *encl) struct sgx_sigstruct *sigstruct = &encl->sigstruct; struct sgx_sigstruct_payload payload; uint8_t digest[SHA256_DIGEST_LENGTH]; + EVP_MD_CTX *ctx = NULL; unsigned int siglen; RSA *key = NULL; - EVP_MD_CTX *ctx; int i; memset(sigstruct, 0, sizeof(*sigstruct)); @@ -384,7 +384,8 @@ bool encl_measure(struct encl *encl) return true; err: - EVP_MD_CTX_destroy(ctx); + if (ctx) + EVP_MD_CTX_destroy(ctx); RSA_free(key); return false; } -- 2.43.0