-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(crypto): mac_context_dtor should free MAC #9119
base: master
Are you sure you want to change the base?
Conversation
In the doc of EVP_MAC_fetch(), https://docs.openssl.org/3.0/man3/EVP_MAC "The returned value must eventually be freed with EVP_MAC_free(3)." This also ensures the same behaviour as in EVP_Q_mac which is used by NIF: crypto:mac/4. note, without this fix there is no memory leak as openssl3 returns the same addr of 'mac' (for the same MAC type), the side effect is the refcnt keeps bumping but I think it still good to have this fix also consider the case where the libcrypto is used by other NIF.
CT Test Results 2 files 14 suites 5m 55s ⏱️ Results for commit 5754f78. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
prefer to use crypto:pbkdf2_hmac to avoid refcnt overflow in OTP26: erlang/otp#9119
@@ -498,6 +498,7 @@ struct mac_context | |||
{ | |||
#if defined(HAS_3_0_API) | |||
EVP_MAC_CTX *ctx; | |||
EVP_MAC *mac; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should better have a global var instead for different alg.
also have a drity but handy tool to reproduce the issue. |
In the doc of EVP_MAC_fetch(), https://docs.openssl.org/3.0/man3/EVP_MAC
"The returned value must eventually be freed with EVP_MAC_free(3)."
This also ensures the same behaviour as in EVP_Q_mac which is used by NIF: crypto:mac/4.
note, without this fix there is no memory leak as openssl3 returns the same addr of 'mac' (for the same MAC type), the side effect is the refcnt keeps bumping but I think it still good to have this fix also consider the case where the libcrypto is used by other NIF.
update: 2nd thought, I think it may have the risk of refcnt overflow.
update: yes. it causes refcnt overflow and triggers double free.