/dev/random or /dev/urandom better under UML?
1 Reply
The reason that /dev/random is considered by some to be unreliable under UML is that it is quite common for it to run out of entropy and block a request for random data. This can leave the requesting process waiting until something happens to generate more entropy. In fact, this problem occurs with all headless systems due to the lack of keyboard and mouse events, which are the most active entropy sources. It may be marginally worse under UML because additional buffering of disk and network i/o further reduces entropy generation.
Obviously, when a Linode shuts down unexpectedly, the urandom PRNG seed does not get saved and at the next boot the previously saved seed is reused. This could become a problem, because /dev/random is particularly heavily used just after boot as things like modssl initialise themselves and request random data, so programs that use /dev/random might block, while those that use /dev/urandom might use predictable data since /dev/random has no entropy and /dev/urandom is reusing an old seed. However, my Linode uses /dev/random for all its random data needs and never seems to block. The only precaution I have taken is to increase the entropy pool size - most distros have a default entropy pool size of 512 bytes - I increase mine to 8k so as to save up randomness during normal operations for the times when sshd and modssl need lots and there's not much else going on to generate it.
To fix it now:````
fremont root # echo 8192 > /proc/sys/kernel/random/poolsize
To change it automatically at boot, add the line:````
kernel.random.poolsize = 8192
to /etc/sysctl.conf .
Saving the PRNG seed periodically with a script to guard against reusing the previous seed in the event of unexpected shutdown only partially mitigates the problem. After a save, the urandom PRNG will generate pseudorandom numbers starting with the saved seed. Following an unexpected shutdown, it will generate the same pseudorandom sequence again.
I recommend using /dev/random with the mods above. If you have problems with it blocking shortly after boot, switch to /dev/urandom. If you do use urandom and you believe reuse of previously saved seeds is a security risk, use a boot script to overwrite the saved PRNG seed with a value obtained from /dev/random. That way, as long as /dev/random had some entropy at some time before an unexpected shutdown, you won't reuse the previously saved seed. Unless the NSA are trying to break into your Linode, this is probably overkill.