News for hackers. Stuff that matters.
Re:Fixing Getrandom() by beefhash on Tuesday October 01, 2019 @02:09PM (#21128691)
There may be some systems where storing entropy in a file across reboots isn't an option, e.g. diskless situations or non-writable filesystems. Though those should be a rare case. Of course, this would actually require cooperation from userspace, and given Linux is just a kernel and userland kind of free to do what they want, it's not as easy as it sounds.

Incidentally, I really wish we could get the arc4random(3) family on GNU/Linux already. It's the only notable *NIX platform that still doesn't provide it; illumos has it, every BSD has it, macOS has it. Given the difficulties with entropy as noted above, however, the whole "non-failing cryptographically secure PRNG" model just won't work with Linux.

Re:Fixing Getrandom() by wahern on Tuesday October 01, 2019 @02:37PM (#21129025)
arc4random almost made it into glibc 2.28:

  https://sourceware.org/ml/libc-alpha/2018-05/msg00891.html
  https://sourceware.org/bugzilla/show_bug.cgi?id=4417
  https://www.openwall.com/lists/musl/2018/07/03/3
That patch was held over for 2.29 but then disappeared.

If glibc had added it then musl libc would have and all would be right with the world, at least from the perspective of userland. The kernel would still need to get its story straight.

Re:Fixing Getrandom() by justin66 on Tuesday October 01, 2019 @03:27PM (#21129538)
The bugzilla is classic Ulrich Drepper. Ugh.
Re:Fixing Getrandom() by hermitdev on Tuesday October 01, 2019 @08:33PM (#21132376)
Some much truth to this. Those that think Linus or RMS are abrassive have obviously never met Drepper.

I once had the (dis)pleasure of meeting him once at a former company when he came onsite and he came across as every bit the condescending asshole as he does on bigzilla. Didn't really get the chance to get to know him as a person, but as they say, first impressions... I get that he's in a tough spot maintaining glibc, but a bit of tack in correspondence would go a long way.

Re:Fixing Getrandom() by dralley on Tuesday October 01, 2019 @10:18PM (#21132914)
His whitepaper on memory is a fantastic read, though (if with a somewhat clickbaity title).

https://www.akkadia.org/drepper/cpumemory.pdf

Re:Fixing Getrandom() by hermitdev on Tuesday October 01, 2019 @10:28PM (#21132964)
I'm not saying he hasn't made contributions to the community. He surely has made more than I have, and very valuable ones at that. I'm just saying interacting with him is not pleasant.
Re:Fixing Getrandom() by throwaway2048 on Tuesday October 01, 2019 @11:53PM (#21133307)
Drepper has been gone from glibc for many years now.
Re:Fixing Getrandom() by AceJohnny2 on Tuesday October 01, 2019 @09:21PM (#21132652)
I figured that the reason the Linux kernel gained popularity originally was because Torvalds was so open about accepting contributions. This compared to BSD which had "standards".

I get where either were coming from (BSD was open-sourcing an established codebase, Linux was a from-scratch effort), but it does seem like that foundational culture persisted.

Sounds like GLibc is more of the latter.

Re:Fixing Getrandom() by hermitdev on Tuesday October 01, 2019 @10:37PM (#21133020)
I see where you're going, but I don't agree we're at the same endpoint. One should generally be accepting of changes, but they should be worthwhile.

Theo de Raat doesn't suffer any fools. He calls bullshit as soon as he sees it (ok, Linis does too) and is fairly uncompromising when it comes to code quality and security regardless of whether it's kernel or userspace.

Seems to me, Linus is primarily focused on kernel space being secure and as long as kernel changes dont break userspace, hes cool.

I appreciate both views, but tend to like Theo's better.

Re:Fixing Getrandom() by anticodon on Wednesday October 02, 2019 @01:48AM (#21133704)
I haven't seen anything criminal in his reply. Can you clarify what's so offending about this discussion, please?
Re:Fixing Getrandom() by lilyball on Wednesday October 02, 2019 @02:27AM (#21133843)
If I submit a patch and get a response like Ulrich's, that's a great way to ensure I'm never going to bother contributing to that project again.
Re:Fixing Getrandom() by asveikau on Wednesday October 02, 2019 @12:29PM (#21138266)
The API was being added to Unix libcs left and right, giving it wide adoption and validation, making it an informal or de facto standard. He was dismissing it as some "dumping ground" code and sarcastically saying "ok, nice work, that would go great in your own project ..."
Re:Fixing Getrandom() by saagarjha on Tuesday October 01, 2019 @03:00PM (#21129275)
> If glibc had added it then musl libc would have

Has musl committed to adding it if glibc does? If not, why would musl add it?

Re:Fixing Getrandom() by wahern on Tuesday October 01, 2019 @03:15PM (#21129420)
See Rich Felker's original message to which Florian Weimer (glibc patch author) replied: https://www.openwall.com/lists/musl/2018/07/02/5

> ... glibc has adding [sic] the arc4random interfaces and it seems reasonable that we should too....

Re:Fixing Getrandom() by bonzini on Tuesday October 01, 2019 @03:50PM (#21129787)
systemd does store the entropy in a file, but Lennart says this in the comments of the article: "we can only credit a random seed read from disk when we can also update it on disk, so that it is never reused. This means /var needs to be writable, which is really later during boot, long after we already needed entropy".

How does OpenBSD deal with this issue?

Re:Fixing Getrandom() by throw0101a on Tuesday October 01, 2019 @08:24PM (#21132330)
From rc(8):

  # Push the old seed into the kernel, create a future seed  and create a seed
  # file for the boot-loader.
  random_seed() {
        dd if=/var/db/host.random of=/dev/random bs=65536 count=1 status=none
        chmod 600 /var/db/host.random
        dd if=/dev/random of=/var/db/host.random bs=65536 count=1 status=none
        dd if=/dev/random of=/etc/random.seed bs=512 count=1 status=none
        chmod 600 /etc/random.seed
  }
* https://cvsweb.openbsd.org/src/etc/rc?rev=1.537

FreeBSD:

* https://svnweb.freebsd.org/base/head/libexec/save-entropy/

* https://www.freebsd.org/cgi/man.cgi?loader.conf(5) (see "entropy_cache_load")

OpenBSD's boot loader also injects entropy into the kernel.

Re:Fixing Getrandom() by devnulloverflow on Tuesday October 01, 2019 @11:10PM (#21133161)
Which is to say, /var/ is writable when they do it.

This business of /var/ not being writable early enough is probably to do with the wonderful complexities of modern Linux, and is just not a problem that OpenBSD has.

Re:Fixing Getrandom() by throw0101a on Wednesday October 02, 2019 @11:37AM (#21137603)
> Which is to say, /var/ is writable when they do it.

They also do it at shutdown, before /var is R/O or unmounted.

One can also have multiple files, and have a regular cron job that replaces one of them occasionally while the system is running. This is what the FreeBSD script does.

* https://svnweb.freebsd.org/base/head/libexec/save-entropy/

* https://svnweb.freebsd.org/base/head/libexec/rc/rc.d/random

Other systems have solved this problem, so I'm not sure why all the high drama with Linux.

Re:Fixing Getrandom() by bonzini on Wednesday October 02, 2019 @10:57AM (#21137141)
What if a filesystem error forces /var (or whichever mount point hosts the entropy seed) to remain read-only and seed is never replaced? Seems like unlike systemd the BSDs are fine with crediting entropy even if it has been used already in a previous boot. That's wrong though.
Re:Fixing Getrandom() by throw0101a on Wednesday October 02, 2019 @11:42AM (#21137661)
> Seems like unlike systemd the BSDs are fine with crediting entropy even if it has been used already in a previous boot.

FreeBSD runs a regular cron job so that there are multiple files. If /var goes R-O, you still have a bunch of files from when it wasn't and they are not the same as on initial boot (assuming that (a) /var was mounted R-W at some point, and (b) cron managed to run as well).

Also, on shutdown there is an attempt to write 4096B to both /entropy and /boot/entropy:

* https://svnweb.freebsd.org/base/head/libexec/rc/rc.d/random?...

Further, all of these various seed files are not the only sources of entropy (timers, RDRAND, etc).

Re:Fixing Getrandom() by bonzini on Thursday October 03, 2019 @03:50AM (#21144651)
> (assuming that (a) /var was mounted R-W at some point

Not a good assumption if the initial r/w mount is the one that fails...

Re:Fixing Getrandom() by throw0101a on Thursday October 03, 2019 @10:36AM (#21147477)
If the initial /var (or /) is broken, then one has bigger problems and probably has to go in manually to fix things.

But for >99% of cases where the system comes up cleanly, and runs cleanly for a period of time, you'll have a bunch of seed files ready to go for the next boot. This configuration optimizes for the common case.

Re:Fixing Getrandom() by asveikau on Wednesday October 02, 2019 @12:27AM (#21133425)
This is a fancy way of saying it's systemd's fault. (/s)
Re:Fixing Getrandom() by loeg on Wednesday October 02, 2019 @02:39AM (#21133894)
FreeBSD saves entropy in two places; the one you've linked is only loaded after userspace starts (via rc.d/random). The boot-time entropy mentioned in loader.conf is also created and saved in rc.d/random:

https://svnweb.freebsd.org/base/head/libexec/rc/rc.d/random?...

Similar idea to what OpenBSD does.

Re:Fixing Getrandom() by tedunangst on Tuesday October 01, 2019 @04:01PM (#21129913)
Read the seed on boot, replace it when possible.
Re:Fixing Getrandom() by magicalhippo on Tuesday October 01, 2019 @07:14PM (#21131914)
It's also said that adding entropy to the pool can never make it worse, no? So why not just add it anyway. If you get to replace it, great! If not, well you tried.
Re:Fixing Getrandom() by bonzini on Wednesday October 02, 2019 @03:14AM (#21134043)
Yes, but you should not credit the entropy you added if you're not sure it's never been used before. And you need to credit it to avoid hangs.
Re:Fixing Getrandom() by sverige on Wednesday October 02, 2019 @04:20AM (#21134335)
OpenBSD doesn't have systemd.
Re:Fixing Getrandom() by throwaway2048 on Tuesday October 01, 2019 @11:55PM (#21133310)
The boot-loader injects randomness into the kernel before starting the kernel (using the saved random seed file), so you can have randomness from the very first bit of initialization.
Re:Fixing Getrandom() by bonzini on Wednesday October 02, 2019 @03:15AM (#21134048)
If you cannot guarantee that the entropy has never been used before, that's bad.
Re:Fixing Getrandom() by throwaway2048 on Wednesday October 02, 2019 @09:37AM (#21136254)
It is guaranteed to not be worse than no injected entropy at all, which is the default and only possible alternative state before the kernel starts, it always gets mixed with what can be gathered.
Re:Fixing Getrandom() by brynet on Tuesday October 01, 2019 @02:17PM (#21128781)
Sure it would, except nobody is brave enough to do it. They're too busy attacking some detail, this week it's diskless situations, next week it's "untrusted" random hardware/rdrand, and ignore a system that mixes components together.
Re:Fixing Getrandom() by beefhash on Tuesday October 01, 2019 @02:33PM (#21128971)
I suppose that's the curse of the success of Linux. Now that it's everywhere, it also has to answer to all kinds of usage scenarios.
Re:Fixing Getrandom() by tedunangst on Tuesday October 01, 2019 @04:50PM (#21130469)
The problem is not intractable if you are willing to solve pieces of it. Then you solve another piece. Then somebody realizes they're the odd man out, and they solve their piece.
Re:Fixing Getrandom() by TorKlingberg on Wednesday October 02, 2019 @05:04AM (#21134559)
Read-only file systems are common in embedded systems, where Linux is often used.