-
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
Backport 2.7: Fix premature fopen() call in mbedtls_entropy_write_seed_file #3821
Conversation
…S#3175 Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
6916cf4
to
d9d484c
Compare
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.
Thank you for making this backport! I have reviewed it, found a single issue and left a comment about it.
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; | ||
|
||
if( ( f = fopen( path, "wb" ) ) == NULL ) | ||
return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ); | ||
if( (mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) |
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 check the return value here like we do on the other two branches:
if( (mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) | |
if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) |
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 return value is checked. It isn't assigned to ret
, but that doesn't matter.
However please do assign to ret
like in the other branches. Keeping the code identical where it's possible makes future backports easier.
Also, Travis CI is failing, could you please check out what the issue is and fix it? |
The 2.7 branch is no longer being maintained, so I am closing this pull request. |
Signed-off-by: Victor Krasnoshchok ct3da21164@protonmail.ch
Description
The PR fixes potential seed file corruption in case if
path
param ofmbedtls_entropy_write_seed_file
is equal toMBEDTLS_PLATFORM_STD_NV_SEED_FILE
(or vice versa; i.e. the same file is used to read from and to write to).Status
READY
Requires Backporting
No
Migrations
NO
Steps to test
MBEDTLS_ENTROPY_NV_SEED
in the active config (config.h
);test_suite_entropy.data
in such a way to makeentropy_seed_file
define the same name asMBEDTLS_PLATFORM_STD_NV_SEED_FILE
(seedfile
by default);test_suite_entropy
target - NV-file related tests should pass.