QAT_Engine icon indicating copy to clipboard operation
QAT_Engine copied to clipboard

a code scanner reports "tbuf" resource leak in qat_prov_rsa_enc_dec.c in qat_prov_rsa_decrypt()

Open nefigtut opened this issue 6 months ago • 7 comments

hi, openscanhub code security scanner reports a resource leak in the qat_prov_rsa_enc_dec.c file in qat_prov_rsa_decrypt():

Defect type: RESOURCE_LEAK QAT_Engine-1.9.0/qat_prov_rsa_enc_dec.c:608:17: leaked_storage: Variable "tbuf" going out of scope leaks the storage it points to.

Indeed, tbuf = OPENSSL_malloc(len) is allocated in qat_prov_rsa_decrypt(). Later an error check and an exit is made without freeing the allocated tbuf: if (!fun) return 0;.

I guess tbuf should be freed here as in other error paths (OPENSSL_free(tbuf);). Or (better, I guess), the tbuf = OPENSSL_malloc(len) allocation should be moved INSIDE the if (qat_hw_rsa_offload || qat_sw_rsa_offload) true branch where it is actually used, and is not used in the false branch.

Could you please have a look and probably fix? Thank you!

nefigtut avatar Jul 03 '25 16:07 nefigtut

Thank you @nefigtut for reporting the issue. I will take a look into this.

venkatesh6911 avatar Jul 07 '25 04:07 venkatesh6911

thank you @venkatesh6911 for a reply and your attention.

nefigtut avatar Jul 08 '25 21:07 nefigtut

Please note that we only use open source analyzers (no Coverity or Snyk) in the public instance of OpenScanHub, so the scan results may vary from internal instance.

siteshwar avatar Jul 09 '25 15:07 siteshwar

@siteshwar this should be another issue, i guess. this is not related to the tbuf issue we're discussing here.

nefigtut avatar Jul 10 '25 18:07 nefigtut

@siteshwar this should be another issue, i guess. this is not related to the tbuf issue we're discussing here.

I am only referencing that the tbuf issue was found through Coverity or Snyk and you may not see it in the public scan results.

siteshwar avatar Jul 11 '25 09:07 siteshwar

@siteshwar oh ok, i see, thank you for the clarification.

nefigtut avatar Jul 11 '25 16:07 nefigtut

Thanks @siteshwar for the info. @nefigtut - We will fix this and other resource leaks in the next release planned.

venkatesh6911 avatar Jul 11 '25 17:07 venkatesh6911