-
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
Scope reduction to enable NULL check to protect dereferencing. #3312
Merged
gilles-peskine-arm
merged 2 commits into
Mbed-TLS:development
from
sander-visser:cleanup-nullptr-deref
May 11, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Bugfix | ||
* Avoid NULL pointer dereferencing if mbedtls_ssl_free() is called with a | ||
NULL pointer argument. Contributed by Sander Visser in #3312. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6661,28 +6661,32 @@ int mbedtls_ssl_context_load( mbedtls_ssl_context *context, | |
*/ | ||
void mbedtls_ssl_free( mbedtls_ssl_context *ssl ) | ||
{ | ||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) | ||
size_t in_buf_len = ssl->in_buf_len; | ||
size_t out_buf_len = ssl->out_buf_len; | ||
#else | ||
size_t in_buf_len = MBEDTLS_SSL_IN_BUFFER_LEN; | ||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN; | ||
#endif | ||
|
||
if( ssl == NULL ) | ||
return; | ||
|
||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> free" ) ); | ||
|
||
if( ssl->out_buf != NULL ) | ||
{ | ||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) | ||
size_t out_buf_len = ssl->out_buf_len; | ||
#else | ||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN; | ||
#endif | ||
|
||
mbedtls_platform_zeroize( ssl->out_buf, out_buf_len ); | ||
mbedtls_free( ssl->out_buf ); | ||
ssl->out_buf = NULL; | ||
} | ||
|
||
if( ssl->in_buf != NULL ) | ||
{ | ||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) | ||
size_t in_buf_len = ssl->in_buf_len; | ||
#else | ||
size_t in_buf_len = MBEDTLS_SSL_IN_BUFFER_LEN; | ||
#endif | ||
|
||
mbedtls_platform_zeroize( ssl->in_buf, in_buf_len ); | ||
mbedtls_free( ssl->in_buf ); | ||
ssl->in_buf = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assignment could be removed as well. |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The whole
ssl
record is unconditionally zeroed at the end of the function.This assignment could be removed.
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.
Indeed. And removing the assignment would also make things more consistent the other allocated structures (transform, session, etc) that we don't explicitly clear.
However IMO this is quite orthogonal to the goal of this PR, so should probably go in a separate PR.