-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Reset dhm_P and dhm_G if config call repeated; avoid memory leak #5353
Reset dhm_P and dhm_G if config call repeated; avoid memory leak #5353
Conversation
Reset dhm_P and dhm_G if call to mbedtls_ssl_config_defaults() repeated to avoid leaking memory. Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
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.
LGTM, thanks!
There's an inconsistency between the labels and the ChangeLog entry as to whether this is a bugfix or an enhancement. I tend to agree that this is a bug: the function's documentation doesn't say that you shouldn't call this more than once, so we should react appropriately if this happens, and at any rate, not leak memory. Bugs need backporting to all maintained branches; currently there's only one: |
Submitted backport to 2.28 in #5416 |
Perfect, thanks! The backport is straightforward (I mean, there were no relevant difference between the two branches that would affect the patch) so only needs one reviewer, but the main PR will need to be reviewed by a second reviewer before both PRs can be merged. |
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.
LGTM.
Description
Reset dhm_P and dhm_G if call to mbedtls_ssl_config_defaults() repeated
to avoid leaking memory.
Signed-off-by: Glenn Strauss gstrauss@gluelogic.com
Status
READY
Requires Backporting
Not required, IMHO, but could be backported. In mbedtls 3.0.0,
mbedtls_ssl_config
membersdhm_P
anddhm_G
are private, so routines underlyingmbedtls_ssl_config_defaults()
should avoid leaking memory ifmbedtls_ssl_config_defaults()
is called more than once. Ifmbedtls_ssl_config_defaults()
is called more than once by an application, then with earlier versions of mbedtls, the application could callmbedtls_mpi_free()
ondhm_P
anddhm_G
.Todos
Other
Test for memory leak not provided.
Observe that
mbedtls_ssl_config_free()
callsmbedtls_mpi_free()
ondhm_P
anddhm_G
conf members.Observe that
mbedtls_ssl_config_defaults()
callsmbedtls_ssl_conf_dh_param_bin()
, and ifmbedtls_ssl_config_defaults()
is called more than once, thenmbedtls_ssl_conf_dh_param_bin()
is called more than once, and insidembedtls_ssl_conf_dh_param_bin()
, conf membersdhm_P
anddhm_G
are overwritten. They should be freed before being overwritten. Observer inmbedtls_ssl_conf_dh_param_bin()
that if there is an error, thenmbedtls_mpi_free()
is called ondhm_P
anddhm_G
conf members. This patch callsmbedtls_mpi_free()
on those members before overwriting them, so that memory is not leaked if the members had previously been allocated.