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 6042677F00; Tue, 23 Jan 2024 02:05: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=1705975523; cv=none; b=q+79o6Lbb5Fwl2xUzEWQDj0fpF/c1HyRnZKyd4YEUtChmqkfhCu80Q9jkuTaz8pq1o0GEsqBEIKd5BxxE13Skz53N/75SvinC+Nx3QiwRmObod7QuFF716d9OvD0VPvcWDGptAlFNSg+ODE1FAWYOMG942FPBWt6A/fc22nnyco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975523; c=relaxed/simple; bh=SIJjYOiSw4MN//RZSZq5DIuoZ0mzIFHjs+3AGI/8VlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TsURYyyVKbgt19FONOC/fqjXmgd8mh8J7UKAHSkziy7QwpzU+W2XikkgH0IEtjFT6naLRP0kWnIzC5eo1bDSZ/Dhe79vL930N3UECxMvmJFPvFb/U0ZiCjBLpM02lkBGvwAu24bHja/xy5N6IMdu77qZFUVII///MwYr3FoWmjU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JxyTAJ96; 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="JxyTAJ96" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26CA6C433C7; Tue, 23 Jan 2024 02:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705975523; bh=SIJjYOiSw4MN//RZSZq5DIuoZ0mzIFHjs+3AGI/8VlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JxyTAJ96ICZWfaTEyU2nirRn77G91qrCb4B3JKFDkDTIYGtF1JirfNDe5WQ/oUD/R +r4WaXnOrclknvX3lnLXNRaKzPSduSBzCPLw6i8aYobUeKDn1I+Vy1UGHhxeW6vjPY VNgRw0SW8O7ztbdcutiPqVX0bq/3RTav3x9hvKWY= 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.6 475/583] selftests/sgx: Fix uninitialized pointer dereference in error path Date: Mon, 22 Jan 2024 15:58:46 -0800 Message-ID: <20240122235826.519543444@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235812.238724226@linuxfoundation.org> References: <20240122235812.238724226@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.6-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