Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qat_hw_sha3.c: resource leak in qat_sha3_session_data_init #294

Open
ColinIanKing opened this issue Jan 12, 2024 · 1 comment
Open

qat_hw_sha3.c: resource leak in qat_sha3_session_data_init #294

ColinIanKing opened this issue Jan 12, 2024 · 1 comment

Comments

@ColinIanKing
Copy link
Contributor

in qat_hw_sha3.c, in function qat_sha3_session_data_init there is a leak of session_data when the call to OPENSSL_zalloc fails:

  session_data = OPENSSL_zalloc(sizeof(CpaCySymSessionSetupData));
   if (NULL == session_data) {
       WARN("session setup data Malloc failure\n");
       QATerr(QAT_F_QAT_SHA3_SESSION_DATA_INIT, QAT_R_SSD_MALLOC_FAILURE);
       return 0;
   }

   /* Set priority and operation of this session */
   session_data->sessionPriority = CPA_CY_PRIORITY_HIGH;
   session_data->symOperation = CPA_CY_SYM_OP_HASH;

   /* Set the hash mode and the length of the digest */
#ifdef QAT_OPENSSL_PROVIDER
   session_data->hashSetupData.hashAlgorithm = qat_get_hash_alg_data(ctx->md_type);
#else
   session_data->hashSetupData.hashAlgorithm = qat_get_hash_alg_data(EVP_MD_CTX_type(ctx));
#endif
   session_data->hashSetupData.hashMode = CPA_CY_SYM_HASH_MODE_PLAIN;
   session_data->hashSetupData.digestResultLenInBytes = sha3_ctx->md_size;
   session_data->hashSetupData.authModeSetupData.authKey = NULL;
   session_data->hashSetupData.nestedModeSetupData.pInnerPrefixData = NULL;
   session_data->hashSetupData.nestedModeSetupData.pOuterPrefixData = NULL;

   /* Tag follows immediately after the region to hash */
   session_data->digestIsAppended = CPA_FALSE;

   /* digestVerify is not required to be set.*/ 
   session_data->verifyDigest = CPA_FALSE;

   pOpData = OPENSSL_zalloc(sizeof(template_opData));
   if (pOpData == NULL) {
       WARN("memory allocation failed for symopData struct.\n");
       QATerr(QAT_F_QAT_SHA3_SESSION_DATA_INIT, ERR_R_MALLOC_FAILURE);
       OPENSSL_free(sha3_ctx->session_data);
       return 0;
   }

^^ the case where pOpData == NULL will return without free'ing session_data

@bjayanax
Copy link
Contributor

@ColinIanKing Thanks for the help. We will check and fix it in upcoming release.

Yogaraj-Alamenda pushed a commit that referenced this issue Mar 26, 2024
- Uninitialized qctx causing driver issue, Change to use OPENSSL_zalloc
   which will take care of initialization to 0.
- Fix Resource Leak in qat_sha3_session_data_init #294

Signed-off-by: Ashwin Basapathy <ashwinx.kumar.basapathy.shivaprasad@intel.com>
Yogaraj-Alamenda pushed a commit that referenced this issue Mar 26, 2024
- Uninitialized qctx causing driver issue, Change to use OPENSSL_zalloc
   which will take care of initialization to 0.
- Fix Resource Leak in qat_sha3_session_data_init #294

Signed-off-by: Ashwin Basapathy <ashwinx.kumar.basapathy.shivaprasad@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants