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

Fix memory leak around the libcrypto boundary #14

Closed
colmmacc opened this issue Sep 2, 2014 · 0 comments
Closed

Fix memory leak around the libcrypto boundary #14

colmmacc opened this issue Sep 2, 2014 · 0 comments
Labels

Comments

@colmmacc
Copy link
Contributor

colmmacc commented Sep 2, 2014

Several functions allocate memory through calls into libcrypto and release it upon successful completion. However the memory is not released under some error conditions which cause
the functions to return early resulting in the memory being leaked.

s2n_dh_compute_shared_secret_as_server() is called by TLS servers every time a client negotiates a session key using integer Diffie-Hellman. It makes one allocation using BN_bin2bn() to hold the client's public key. If the public key is invalid (for instance, all zeroes) the call to DH_compute_key will fail resulting in pub_key memory not being freed. With enough invocations, this could lead to memory exhaustion.

The function s2n_asn1der_to_rsa_public_key() decodes a DER-encoded certificate and extracts an RSA public key from it. Two memory allocations are made in this function by the calls to d2i_X509() and X590_get_pubkey(). Both are correctly released when the function returns. However it can return early under a few error conditions, such as if the certificate does not contain an RSA public key. In these cases the allocations are leaked. At the moment this leak affects only TLS clients since this function is only called on clients.

s2n_pkcs3_to_dh_params() is used to load integer Diffie-Hellman parameters on TLS servers. It makes one allocation using d2i_DHparams() which is not cleaned up if the parameters contain extraneous data. This function is only called during server start-up so it does not appear to be remotely exploitable.

@colmmacc colmmacc added the bug label Sep 2, 2014
@colmmacc colmmacc closed this as completed Sep 2, 2014
colmmacc added a commit that referenced this issue Sep 3, 2014
This change frees libcrypto resources when they are semantically
incorrect and trigger error branches.

Resolves bug #14
colmmacc added a commit that referenced this issue Jun 29, 2015
This change frees libcrypto resources when they are semantically
incorrect and trigger error branches.

Resolves bug #14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant