4 ms·
> but some do it anyway—for example, to create entropy Ouch! This is a really terrible idea and people should stop doing it in C. It's a bad entropy source as,
by pjc50 10y ago
> but some do it anyway—for example, to create entropy
Ouch! This is a really terrible idea and people should stop doing it in C. It's a bad entropy source as, unless you're very specific about the hardware, you have no idea what you're going to get. Maybe it is all zeroes. Maybe it's a page of a previously executed program.
If you're going to do this, do it in assembler so it's deliberately unportable.
- DubiousPusher 10y agoOk, couple questions. Entropy in what context? Just as a source of randomness? Which isn't what entropy really is right? Either way it seems unlikely to be very random. In my experience 0 is by far the most common value in unitialized memory, to the point of making many uninitialized memory bugs difficult to notice or even later reproduce.
- minipci1321 10y ago> In my experience 0 is by far the most common value in unitialized memory, In BSS, yes (IMO, BSS cannot be really considered as uninitialized, but you didn't give precisions). On the stack... I don't remember offhand whether the thread's stack is initially mapped in using zeropage which is then replaced by a real page on a first write. Even so, the first write would be saving the return address, so occurring pretty quickly. In any case, code moving up and down along the stack (calling into a chain of embedded routine inside a loop) will mostly spot its own garbage, hardly entropic.
- TazeTSchnitzel 10y agoIt always struck me that there's a good chance it's completely or mostly predictable, if you end up grabbing something your program produced.
- mikeash 10y agoFor those who don't remember, the infamous Debian bug which resulted in weak keys being generated on Debian systems for a couple of years stemmed from this. Using uninitialized memory wasn't an actual problem there, as it was mixed in with a bunch of other entropy before being used, and those other sources were sufficient even if the uninitialized memory had predictable contents. However, tools like Valgrind complained about it, so somebody fixed it, and inadvertently wiped out almost all of the other entropy sources going into it as well.
- nullc 10y agoThe story is even more interesting. OpenSSL did that _and still does it today_. As a result any program that uses the OpenSSL RNG is full of spurious valgrind errors (exactly what you want in security critical code...). It had (and still has) a -DPURIFY flag available at compile time that gets rid of that stupidity, which is still not default. OpenSSL have not changed it, as I understand, because of a concern that there might exist some embedded system somewhere where that is the only useful source of randomness. A debian developer saw the errors all over the place, wrote a patch to fix it. The patch, unfortunately, went to far and managed to knock out the secure randomness source to. The patch was posted to the OpenSSL list and no one responded "No don't!" or "Have you seen the already existing DPURIFY?"... and the rest is history. Fedora, at least, adds DPURIFY, but many other distributions do not.
- mikeash 10y agoOh wow, I didn't realize the option was still there, let alone on by default. Madness. The embedded system argument makes no sense to me (understanding that you're just repeating it, not defending it). If there's no other source of randomness then there's no good source of randomness, period, and you're screwed. Better not to even try, then.