Skip to content

Comments

Don't open random devices while cleaning up.#7023

Closed
mspncp wants to merge 2 commits intoopenssl:masterfrom
mspncp:pr-fix-random-device-handle-leak
Closed

Don't open random devices while cleaning up.#7023
mspncp wants to merge 2 commits intoopenssl:masterfrom
mspncp:pr-fix-random-device-handle-leak

Conversation

@mspncp
Copy link
Contributor

@mspncp mspncp commented Aug 21, 2018

Fixes #7022

In pull request #6432 a change was made to keep the handles to the
random devices opened in order to avoid reseeding problems for
applications in chroot environments.

As a consequence, the handles of the random devices were leaked at exit
if the random generator was not used by the application. This happened,
because the call to RAND_set_rand_method(NULL) in rand_cleanup_int()
triggered a call to the call_once function do_rand_init, which opened
the random devices via rand_pool_init(void).

Thanks to GitHub user @bwelling for reporting this issue.

Fixes openssl#7022

In pull request openssl#6432 a change was made to keep the handles to the
random devices opened in order to avoid reseeding problems for
applications in chroot environments.

As a consequence, the handles of the random devices were leaked at exit
if the random generator was not used by the application. This happened,
because the call to RAND_set_rand_method(NULL) in rand_cleanup_int()
triggered a call to the call_once function do_rand_init, which opened
the random devices via rand_pool_init(void).

Thanks to GitHub user @bwelling for reporting this issue.
@mspncp mspncp force-pushed the pr-fix-random-device-handle-leak branch from 8d4486a to a18990d Compare August 21, 2018 21:25
@mspncp mspncp requested a review from paulidale August 21, 2018 21:28
meth->cleanup();
rand_pool_cleanup();
RAND_set_rand_method(NULL);
rand_pool_cleanup();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapping these two lines was my first attempt to fix the problem. However, the result was not satisfactory, because the devices were still opened by RAND_set_rand_method() and closed right afterwards in rand_pool_cleanup(). That's why I introduced rand_cleaning_up.

So strictly speaking this swapping is not necessary anymore, but conceptually it makes more sense to cleanup the entropy source after the random generator has been disabled and not before.


if (!rand_pool_init())
goto err3;
if (!rand_cleaning_up)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better might be using && rather than nesting the if statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixed!

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor cleaning but it's not vital.

@mspncp mspncp added the approval: done This pull request has the required number of approvals label Aug 22, 2018
@mspncp
Copy link
Contributor Author

mspncp commented Aug 22, 2018

I'll merge this evening.

@mspncp
Copy link
Contributor Author

mspncp commented Aug 22, 2018

Editorial note: I intend to apply two small cosmetical changes to the commit message when merging:

Don't open random devices while cleaning up.
->
rand_lib.c: Don't open random devices while cleaning up.
the random devices via rand_pool_init(void).
->
the random devices via rand_pool_init().

levitte pushed a commit that referenced this pull request Aug 22, 2018
Fixes #7022

In pull request #6432 a change was made to keep the handles to the
random devices opened in order to avoid reseeding problems for
applications in chroot environments.

As a consequence, the handles of the random devices were leaked at exit
if the random generator was not used by the application. This happened,
because the call to RAND_set_rand_method(NULL) in rand_cleanup_int()
triggered a call to the call_once function do_rand_init, which opened
the random devices via rand_pool_init().

Thanks to GitHub user @bwelling for reporting this issue.

Reviewed-by: Paul Dale <[email protected]>
(Merged from #7023)
@mspncp
Copy link
Contributor Author

mspncp commented Aug 22, 2018

Ok, merged. Thanks!

@mspncp mspncp closed this Aug 22, 2018
@mspncp mspncp deleted the pr-fix-random-device-handle-leak branch October 22, 2018 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants