Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/sgx: Fix uninitialized pointer dereference in error path

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 <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

authored by

Jo Van Bulck and committed by
Dave Hansen
79eba8c9 33cc938e

+3 -2
+3 -2
tools/testing/selftests/sgx/sigstruct.c
··· 318 318 struct sgx_sigstruct *sigstruct = &encl->sigstruct; 319 319 struct sgx_sigstruct_payload payload; 320 320 uint8_t digest[SHA256_DIGEST_LENGTH]; 321 + EVP_MD_CTX *ctx = NULL; 321 322 unsigned int siglen; 322 323 RSA *key = NULL; 323 - EVP_MD_CTX *ctx; 324 324 int i; 325 325 326 326 memset(sigstruct, 0, sizeof(*sigstruct)); ··· 384 384 return true; 385 385 386 386 err: 387 - EVP_MD_CTX_destroy(ctx); 387 + if (ctx) 388 + EVP_MD_CTX_destroy(ctx); 388 389 RSA_free(key); 389 390 return false; 390 391 }