Skip to content

Commit

Permalink
selftests/sgx: Fix uninitialized pointer dereference in error path
Browse files Browse the repository at this point in the history
[ Upstream commit 79eba8c ]

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: 2adcba7 ("selftests/x86: Add a selftest for SGX")
Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Acked-by: Kai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/all/20231005153854.25566-2-jo.vanbulck%40cs.kuleuven.be
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
jovanbulck authored and gregkh committed Jan 25, 2024
1 parent 9a662d0 commit ea6a3d6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/testing/selftests/sgx/sigstruct.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

0 comments on commit ea6a3d6

Please sign in to comment.