News for hackers. Stuff that matters.
Re:OpenSSH taking minutes to become available, booting takes... by deathanatos on Wednesday July 17, 2019 @05:03PM (#20463996)
Seems like they store entropy in an on-disk file[1], and re-read that file on startup. This feature is available in Linux as well (see urandom(4) for an example of how to do it manually, though I think most distros bundle this in some manner); although apparently, according to the OP, it doesn't fully work?

Seems like the man page sort of notes the problem in the article:

> Writing to /dev/random or /dev/urandom will update the entropy pool with the data written, but this will not result in a higher entropy count.

But, why not, man page, why not? I feel like if I, as root, write to /dev/random, I am saying that this is acceptable input for seeding the generator, and that it is on me to not, say, seed it with the exact same stuff every boot, or seed it with straight nuls, no?

How does OpenBSD guarantee that this file exists, though? Perhaps making it a system default is wise, but what about brand new VMs/installs? Does the install just take the time to do the first generation of that file?

The OpenBSD folks also appear to trust RDRANG, which would help not blocking. But I disagree with that trust decision.

[1]: start reading here: https://www.openbsd.org/papers/hackfest2014-arc4random/mgp00...

Re:OpenSSH taking minutes to become available, booting takes... by notaplumber on Wednesday July 17, 2019 @05:09PM (#20464048)
> The OpenBSD folks also appear to trust RDRANG, which would help not blocking. But I disagree with that trust decision.

It feeds the entropy pool, mixed in with many sources. OpenBSD also feeds in data from the AMD CCP as well. The point is it doesn't matter.

https://man.openbsd.org/ccp

And anyone running "echo badapples > /dev/random" in a loop, it still doesn't matter.

https://man.openbsd.org/random.4

https://man.openbsd.org/arc4random.9

> How does OpenBSD guarantee that this file exists, though?

If you keep reading, OpenBSD's random subsystem always mixes old with new data from many sources. If the random.seed file is not available (for example, boot media), it is not fatal. There is a warning displayed. But the system rc(8) scripts handle creating the seed file at both boot and shutdown.

https://www.openbsd.org/papers/hackfest2014-arc4random/mgp00...

Re:OpenSSH taking minutes to become available, booting takes... by deathanatos on Wednesday July 17, 2019 @06:05PM (#20464520)
> If you keep reading, OpenBSD's random subsystem always mixes old with new data from many sources.

Sure. But say we don't trust RDRAND. It's the first boot, so you haven't got a seed file yet. Assuming you haven't got a HW generator at hand, what other source are there that don't take significant time to collect from? (I.e., I know you can get it from network timings, keyboard/mouse if they exist, etc., but that takes time, and would cause a call not wanting to return prior to there being sufficient data to block. If you're only mixing in unready or untrusted sources, you might get lucky and make it hard for an attacker, or worse, if your other sources are blocking b/c they're collecting data… you might not, but regardless it hardly seems principled?)

It'd be willing to write off the first boot, except that I feel like a lot of things do potentially get initialized then; e.g., in a VM in the cloud, I think that's when host keys are initialized, for example, and certainly whatever application that VM might be hosting could have further requirements. Not blocking and issuing a warning would be to supply data prior to having sufficiently initialized a generator, no?

Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Wednesday July 17, 2019 @06:15PM (#20464590)
> Sure. But say we don't trust RDRAND. It's the first boot, so you haven't got a seed file yet.

Why not? The install media should be collecting entropy as it does the install, xoring it with a pool of random data built into it, and writing that to disk as part of the install.

Take a look at https://github.com/openbsd/src/blob/master/distrib/miniroot/..., specifically, feed_random and store_random

Re:OpenSSH taking minutes to become available, booting takes... by rasz on Wednesday July 17, 2019 @09:24PM (#20465779)
>Why not? The install media should be collecting entropy as it does the install, xoring it with a pool of random data built into it, and writing that to disk as part of the install.

and during first reboot you image the disk and flash it into millions of routers, resulting in something like https://devcraft.io/posts/2017/07/21/tp-link-archer-c9-admin...

Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Wednesday July 17, 2019 @09:36PM (#20465875)
Thank god OpenBSD mixes in data from hardware RNGs, and the bootloader collects entropy as part of the boot process, effectively turning that exploit vector into a state level attack.
Re:OpenSSH taking minutes to become available, booting takes... by Dylan16807 on Wednesday July 17, 2019 @09:54PM (#20465976)
But if you're imaging a drive and also RDRAND fails, OpenBSD is just as vulnerable to attack. See also AMD for RDRAND failing entirely.
Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Wednesday July 17, 2019 @09:59PM (#20466004)
Yeah, that's why the bootloader also gathers entropy as it's coming up.

But, at some point nobody can save you from yourself entirely. Get a broken enough system, and every security feature will fail.

Re:OpenSSH taking minutes to become available, booting takes... by Dylan16807 on Wednesday July 17, 2019 @10:05PM (#20466043)
The bootloader collects some, but I doubt it reliably collects enough all by itself.
Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Wednesday July 17, 2019 @10:47PM (#20466256)
How much do you think is enough, and why do you think the amount collected during boot is insufficient?
Re:OpenSSH taking minutes to become available, booting takes... by Dylan16807 on Wednesday July 17, 2019 @10:55PM (#20466292)
Let's say 300 bits.

I'm assuming a bootloader can't collect more in three seconds than an OS can collect in multiple minutes. Is that assumption wrong?

If it's the design of the code that lets it collect entropy faster, then it's that code that needs to be ported, and it doesn't matter if it's in a bootloader or not except to save a second or two.

Re:OpenSSH taking minutes to become available, booting takes... by vbezhenar on Thursday July 18, 2019 @01:17AM (#20466946)
300 true random bits is a lot. Even something like 128 bits is unbreakable with available hardware.
Re:OpenSSH taking minutes to become available, booting takes... by deathanatos on Wednesday July 17, 2019 @06:19PM (#20464616)
Okay, that's fair for install media installing to a physical machine such as a desktop.

What about virtual machines / machines booting off an image? We can't put a seed in the image, or it'll get distributed to all downstream consumers.

Also, there's the case posed in response to my first comment, about IOT devices which would ship with some factory-installed image.

(I suppose there are some novel ways one could work around this such as somehow keeping a pool of one-shot images ready w/ just the seed added to them, but I don't feel like this is how real-world systems work. E.g., an AMI in AWS?)

Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Wednesday July 17, 2019 @06:36PM (#20464734)
> What about virtual machines / machines booting off an image? We can't put a seed in the image, or it'll get distributed to all downstream consumers.

Mitigations within mitigations.

Having one random seed per VM image that gets installed is better than having nothing at all -- now, an attacker needs to have your install image. Then the hardware RNG and the virtio random drivers help mix into that seed.

Given that presumably you've already booted the image for testing, you've probably already generated the SSH keys that you need to be concerned about -- so you'd probably need to take care to regenerate them securely in any case, from a running system that has started to gather entropy from all the sources it can get its hands on, including the boot loader.

And, ideally part of the imaging process would write some random data to the image. But I agree, most people wouldn't even think of doing that.

Re:OpenSSH taking minutes to become available, booting takes... by aquabeagle on Wednesday July 17, 2019 @06:25PM (#20464663)
Re:OpenSSH taking minutes to become available, booting takes... by wbl on Wednesday July 17, 2019 @06:33PM (#20464707)
HW rng is essential then
Re:OpenSSH taking minutes to become available, booting takes... by tytso on Wednesday July 17, 2019 @05:30PM (#20464253)
/dev/random and /dev/urandom are world-writeable by design. This allows anyone to contribute to randomness via "cat ~/my_secrets > /dev/random". Of course, my_secrets might not be very secret, or controlled by the attacker. So there is no credit given to that.

There is a way for a root process, like systemd, to contribute trusted entropy to the entropy pool, using an ioctl. Of course, then it is systemd which will be taking on the responsibility if it turns out that /var/lib/random_seed turns out to be replicated onto a zillion static images on some IOT device, so it turns out /var/lib/random_seed wasn't actually all that random to begin with

Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Wednesday July 17, 2019 @06:12PM (#20464564)
> The OpenBSD folks also appear to trust RDRANG, which would help not blocking. But I disagree with that trust decision.

Mixing more data into a random source cannot make it worse. OpenBSD does not use rdrand alone.

Re:OpenSSH taking minutes to become available, booting takes... by nitrogen on Thursday July 18, 2019 @12:29AM (#20466710)
This is unlikely, but wouldn't it be conceivable that a malicious hardware "RNG" that lives in the CPU and has access to the internal state of the OS RNG (and knows common OS algorithms) could always supply the worst possible value to counteract whatever is in the pool?
Re:OpenSSH taking minutes to become available, booting takes... by ori_b on Thursday July 18, 2019 @01:34AM (#20467016)
Yeah, but you don't need to use rdrand in that scenario -- the cpu could also just tamper with the pool at will, regardless of the RDRAND instruction.
Re:OpenSSH taking minutes to become available, booting takes... by lifthrasiir on Thursday July 18, 2019 @03:57AM (#20467739)
djb has noted that RDRAND is a particularly attractable means to exfiltration back in 2014 [1]. So it is not simply irrelevant.

[1] https://blog.cr.yp.to/20140205-entropy.html

Re:OpenSSH taking minutes to become available, booting takes... by earenndil on Wednesday July 17, 2019 @05:25PM (#20464201)
I believe they xor the output of rdrand with that of other randomness sources; meaning, they don't have to trust that its output is actually random.
Re:OpenSSH taking minutes to become available, booting takes... by justincormack on Wednesday July 17, 2019 @06:00PM (#20464485)
There is an ioctl to write with an ascribed entropy from Linux.