Skip to content

Conditionally open random devices on initialisation.#7429

Closed
paulidale wants to merge 1 commit intoopenssl:masterfrom
paulidale:fix-7419
Closed

Conditionally open random devices on initialisation.#7429
paulidale wants to merge 1 commit intoopenssl:masterfrom
paulidale:fix-7419

Conversation

@paulidale
Copy link
Contributor

@paulidale paulidale commented Oct 17, 2018

The rand_pool_init function was always opening the random devices regardless of the keep them open setting. Now, it conditionally opens them.

Fixes #7419

@mspncp
Copy link
Contributor

mspncp commented Oct 18, 2018

Looks good to me at first sight, but I'd like to check the code example in detail in the debugger...

@mspncp
Copy link
Contributor

mspncp commented Oct 18, 2018

Pauli, I did a lot of debugging and testing today and the result is an alternative proposal for fixing issue #7419. Instead of opening the random devices unconditionally, my approach is to open them only on first use. This has the advantage that in the case where the getrandom() system call is available, no file handles will be opened unnecessarily. This works without requiring that the application calls RAND_keep_random_devices_open(0);

This change does not reintroduce a regression for chroot applications compiled with 1.1.0, since the SSLEAY RNG also reseeds on first use. For full details, see pull request #7437

@petrovr
Copy link

petrovr commented Oct 19, 2018 via email

@mspncp
Copy link
Contributor

mspncp commented Oct 20, 2018

Roumen, I'm not sure in which direction your comment goes, could you explain it a bit more, please?

The problem you are pointing to has been discussed and addressed in #6432:

/*
* Verify that the file descriptor associated with the random source is
* still valid. The rationale for doing this is the fact that it is not
* uncommon for daemons to close all open file handles when daemonizing.
* So the handle might have been closed or even reused for opening
* another file.
*/
static int check_random_device(struct random_device * rd)
{
struct stat st;
return rd->fd != -1
&& fstat(rd->fd, &st) != -1
&& rd->dev == st.st_dev
&& rd->ino == st.st_ino
&& ((rd->mode ^ st.st_mode) & ~(S_IRWXU | S_IRWXG | S_IRWXO)) == 0
&& rd->rdev == st.st_rdev;
}

Neither #7429 nor #7437 changes anything in that matter.

@petrovr
Copy link

petrovr commented Oct 22, 2018 via email

@mspncp mspncp added branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) labels Oct 28, 2018
@mspncp mspncp added this to the 1.1.1a milestone Oct 28, 2018
for (i = 0; i < OSSL_NELEM(random_devices); i++)
random_devices[i].fd = -1;
open_random_devices();
if (keep_random_devices_open)
Copy link
Member

Choose a reason for hiding this comment

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

I have an issue with this change.
This assumes that rand_pool_keep_random_devices_open is called before
rand_pool_init but that cannot work, because rand_pool_keep_random_devices_open
calls either open_random_devices or rand_pool_cleanup, and those operate
on uninitialized data random_devices. I believe it is a severe bug that
RAND_keep_random_devices_open does not call RUN_ONCE(&rand_init, do_rand_init));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This is a separate problem and I'll create a new PR to fix it -- we've not reached a decision as to including this PR or using #7437 instead.

@paulidale
Copy link
Contributor Author

Closing in favour of #7437

@paulidale paulidale closed this Nov 7, 2018
@paulidale paulidale deleted the fix-7419 branch November 7, 2018 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants