Message ID | 20230808193145.8860-2-jo.vanbulck@cs.kuleuven.be (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | selftests/sgx: Fix compilation errors | expand |
On Tue Aug 8, 2023 at 10:31 PM EEST, Jo Van Bulck wrote: > 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> > --- > 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.34.1 Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> BR, Jarkko
On Tue, 2023-08-08 at 12:31 -0700, Jo Van Bulck wrote: > 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> > --- > 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; > } Acked-by: Kai Huang <kai.huang@intel.com>
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; }
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> --- tools/testing/selftests/sgx/sigstruct.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)