dhardy / rand

http://doc.rust-lang.org/rand
Other
2 stars 2 forks source link

WIPEONFORK [Linux] #59

Closed dhardy closed 6 years ago

dhardy commented 6 years ago

We could maybe make use of this, e.g. as a wrapper around a CSPRNG: https://aws.amazon.com/blogs/opensource/better-random-number-generation-for-openssl-libc-and-linux-mainline/

Unfortunately it sounds like it's only available on one platform.

pitdicker commented 6 years ago

I think this could work well as part of ReseedingRng.

For WIPEONFORK to work you need to check some value against zero, and need to have a seeding RNG. ReseedingRng already needs to check a bytes_generated counter against generation_threshold, and has a reseeder. We would just have to invert the counter and back-off logic. That may even make it slightly faster, because comparing against 0 is slightly faster than checking against a value.

Is failing to reseed after a fork a case we want to handle, or exceedingly rare? We are talking here about a feature for a very recent Linux kernel version, and for OpenBSD. Both have an OS RNG that is supposed to be infallible. And if ReseedingRng is combined with ReseedWithNew it will have JitterRng as a backup. So I think we do not need to do something extra to the error handling ReseedingRng already has.

Advantages of using a custom wrapper:

Advantages of using ReseedingRng instead of a custom wrapper:

dhardy commented 6 years ago

It's possible to have the WIPEONFORK protection with ReseedingRng even without extra reseeding: just set the reseed threshold very high. The converse isn't true unless WIPEONFORK is configurable, but I can't see why users would not want this if using ReseedingRng. So sounds like a good idea to me.

pitdicker commented 6 years ago

I have experimented with this, but couldn't get it to work yet on Fedora 27. I am not sure if it was my code, or if the necessary libraries are not yet recent enough.

burdges commented 6 years ago

Isn't WIPEONFORK applied to entire pages? Is there any scheme for aggregating allocations that want similar page flags?