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

Backport 2.7: Fix premature fopen() call in mbedtls_entropy_write_seed_file #3821

Closed

Conversation

militant-daos
Copy link
Contributor

Signed-off-by: Victor Krasnoshchok ct3da21164@protonmail.ch

Description

The PR fixes potential seed file corruption in case if path param of mbedtls_entropy_write_seed_file is equal to MBEDTLS_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

  1. Define MBEDTLS_ENTROPY_NV_SEED in the active config (config.h);
  2. Edit test_suite_entropy.data in such a way to make entropy_seed_file define the same name as MBEDTLS_PLATFORM_STD_NV_SEED_FILE (seedfile by default);
  3. Build and run test_suite_entropy target - NV-file related tests should pass.

…S#3175

Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
Copy link
Contributor

@yanesca yanesca left a 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 )
Copy link
Contributor

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:

Suggested change
if( (mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 )
if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 )

Copy link
Contributor

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.

@yanesca yanesca added Community needs-reviewer This PR needs someone to pick it up for review needs-work bug labels Oct 26, 2020
@yanesca yanesca added the needs-ci Needs to pass CI tests label Oct 26, 2020
@yanesca
Copy link
Contributor

yanesca commented Oct 26, 2020

Also, Travis CI is failing, could you please check out what the issue is and fix it?

@gabor-mezei-arm gabor-mezei-arm self-requested a review October 26, 2020 09:31
@gilles-peskine-arm gilles-peskine-arm changed the title Fix premature fopen() call in mbedtls_entropy_write_seed_file #3175 Backport 2.7: Fix premature fopen() call in mbedtls_entropy_write_seed_file Nov 3, 2020
@gilles-peskine-arm
Copy link
Contributor

The 2.7 branch is no longer being maintained, so I am closing this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review needs-work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants