-
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
Conversation
CT Test Results 2 files 14 suites 5m 48s ⏱️ Results for commit f2acfa0. ♻️ 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
also have a drity but handy tool to reproduce the issue. |
I pushed a commit to your branch where EVP_MAC_fetch is called once when crypto module is loaded and EVP_MAC_free called when it's unloaded. |
@sverker LGTM. Feel free to drop my branch if you want a clean PR. |
@qzhuyan I suggest you squash the two commits into one and set yourself as |
9d3352a
to
fceb55c
Compare
hi, is there anything needed from my side? |
fceb55c
to
7b3675f
Compare
My apologies, I just found I used the wrong author's name. |
@qzhuyan I forgot about this. It just missed the code freeze for OTP 28.0-rc1. My bad. I will merge it later for inclusion in 28.0-rc2. |
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)." Co-authored-by: Sverker Eriksson <[email protected]> Co-authored-by: William Yang <[email protected]>
7b3675f
to
f2acfa0
Compare
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.