r/linux • • Mar 01 '22

Linux 5.18 will likely have a blocking /dev/urandom such that calls to the RNG will *always* return secure bytes after initial seeding, which takes no more than 1s after boot. After decades of confusion, all random interfaces will finally be identical.

https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git/commit/?id=2ad310f93ec3d7062bdb73f06743aa56879a0a28
1.5k Upvotes

236 comments sorted by

View all comments

Show parent comments

29

u/atoponce Mar 01 '22 edited Mar 02 '22

First, the blocking pool was removed in version 5.6. /dev/random no longer blocks.

Second, the entropy estimating accounting process determines when to rekey ChaCha20. If the entropy estimate has reached 256 bits and the duration between rekeying is 5 minutes, only then will the RNG be rekeyed.

Third, the blocking now is happening with any call to the RNG only before it's been seeded, getrandom(), /dev/random, or /dev/urandom. After it's been seeded, which happens very early in boot, calls to the RNG will no longer block.

Edit: correction

-2

u/leahlemonlime Mar 01 '22

Serious question-- if neither device blocks after boot anymore, does that mean that systems with low entropy will have insecure random data, as there is no check for entropy?

4

u/za419 Mar 01 '22

It will block if there's no entropy.

The thing is that the modern kernel is very good at getting entropy, and it's also very good at stretching it out - 256 bits of entropy key the generator, and then it can produce a TON of cryptographically secure randomness out of that 256 bits before it needs to be rekeyed with another 256 bits.

So the only realistic time it is going to block will be within about a second of boot, while the kernel is still collecting its initial entropy - and it'd just be poor form anyway to rely on that sort of timing early in startup.

4

u/atoponce Mar 01 '22

Your init system (systemd, Upstart, SysV, etc.) is likely busy getting daemons started during the first second or two. Before the first userspace daemon starts, there's very high confidence via jitter entropy that the kernel has already been sufficiently seeded. So things like your VPN, HTTPS, or SSH server are guaranteed to get cryptographically secure bits.

1

u/za419 Mar 01 '22

Right.

If it was "a second after the user perceives the system as fully booted", ie when the window manager shows you a login screen, that'd be bad - but by then the kernel has seen the system booted for a while. You'd probably have to go out of your way to come up with a service that's affected by this change - which is why Torvalds approved it, as he despises breaking userspace.

4

u/atoponce Mar 01 '22

No, because if the RNG is not blocking, it was seeded with 256 bits of information theoretic secure entropy. After this commit, if the RNG returns data, it's indistinguishable from true random white noise.