-
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
premature fopen in entropy_write_seed_file() #3175
Comments
Hi @geecrypt , I'd like to work on this issue but I do not see any problems with mbedtls_entropy_write_seed_file() logic itself. To be precise, taking into account all the supplied tests I cannot consider a straightforward way to open a seed file more than once during mbedtls_entropy_write_seed_file() call. Could you please elaborate bit on what should be done to trigger this behavior? The only possible case for the file to be corrupted IMHO if one of our entropy sources opens the same file to read from it while it being already opened by mbedtls_entropy_write_seed_file but I doubt this is a valid use-case which MbedTLS should handle by itself (I believe that the users of the library are responsible for entropy sources they implement in terms of behavior correctness). Please correct me if I'm wrong. Thanks in advance. In general I agree with you about moving fopen() call below mbedtls_entropy_func() besides the described problem with corruption: since in case if mbedtls_entropy_func fails there is no sense in opening an output file at all - we may skip this action saving some time not doing the syscall. @gilles-peskine-arm CC. This is my first attempt to contribute to this project so I may ask some stupid questions :-) |
I think I see the problem:
This may be a user error, though. Does it really make sense to call We can't portably detect whether two files are the same, so it isn't a condition that we can detect at runtime. We can only document that you shouldn't do this. @geecrypt Is there a problem if @militant-daos Feel free to ask, either on GitHub or on the mailing list. I'm aware that there are many things we don't document. We're working on it. |
…S#3175 Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
@gilles-peskine-arm thanks for the explanation. Yes, you're right - I did not define Looks like the only way to break things is to make I have created a PR for this - #3616 . In case if you consider this issue as the one which does not need to be fixed please fell free to abandon it and I'll look for another one to work on. |
I agree, it is not a supported use case, but there is nothing stopping users to do that. When the That said, it is hard to say if or when that will happen and given that we have a fix available (thank you @militant-daos!), I suggest we fix this. |
Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
@gilles-peskine-arm Another example:
|
Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
…S#3175 Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
…S#3175 Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
Signed-off-by: Victor Krasnoshchok <ct3da21164@protonmail.ch>
Description
Bug
mbedtls_entropy_write_seed_file() opens the seed file before calling entropy_func() to grab some entropy.
The issue occurs when the user has added a seed file poll function as a custom entropy poll source. When gathering entropy from available sources, fopen() will then be called again on an already open file. This can result in file corruption.
This could be fixed by moving fopen() after the call to entropy func() in mbedtls_entropy_write_seed_file().
The text was updated successfully, but these errors were encountered: