News for hackers. Stuff that matters.
Re:Some AMD CPU's RDRAND might not return random data after ... by lelf on Tuesday May 07, 2019 @11:32AM (#19850448)
RDRAND is not guaranteed to always succeed (and never was). You’re supposed to retry on failure.

(Although linked in that thread systemd code has fallback anyway, so I’m not sure how it fails at all).

Edit: not to mention that it’s better just to not use it, ever. Quite sane and sensible thing.

Re:Some AMD CPU's RDRAND might not return random data after ... by JdeBP on Tuesday May 07, 2019 @01:44PM (#19851693)
The instruction is signalling success, but returning FFFFFFFFFFFFFFFF as the random value.

* https://github.com/systemd/systemd/issues/11810#issuecomment...

H. Peter Anvin's educated guess was that some MSR flag, that has the effect of controlling this instruction, is not being saved and restored in the processor across a suspend, and the result is a processor state where it signals that the instruction is succeeding but it is not actually returning random values.

* https://bugzilla.kernel.org/show_bug.cgi?id=85911#c4

Re:Some AMD CPU's RDRAND might not return random data after ... by lelf on Tuesday May 07, 2019 @02:17PM (#19852014)
> The instruction is signalling success

Let’s wait for clarifications how that person has done the tests.

However: the bug is about systemd failing to get entropy, not getting nonsense entropy.

Re:Some AMD CPU's RDRAND might not return random data after ... by JdeBP on Tuesday May 07, 2019 @02:54PM (#19852316)
How xe was doing this was in fact explained in the comment hyperlinked right at the start of this page, and H. Peter Anvin was thinking about this over 4 years ago. But for the doubters Vladislav has already reiterated the point.

* https://github.com/systemd/systemd/issues/11810#issuecomment...

There is no "however". This bug is about code that is, according to the AMD doco, using the instruction correctly; but that is, because the AMD processor has this possible state after a suspend+resume, getting all-ones as its random data, thereby causing ID collisions in a fairly wide range of possible things from freshly re-generated machine IDs to journal file header block IDs, and including unit invocation IDs.

* https://github.com/systemd/systemd/blob/717e8eda77b93ac396dc...

* https://github.com/systemd/systemd/blob/717e8eda77b93ac396dc...

* https://github.com/systemd/systemd/blob/717e8eda77b93ac396dc...

This indicates that a "should be fine" in another comment is not in fact true. (-:

* https://github.com/systemd/systemd/blob/717e8eda77b93ac396dc...

Re:Some AMD CPU's RDRAND might not return random data after ... by zaroth on Wednesday May 08, 2019 @03:51PM (#19862249)
The Bugzilla report seemed to indicate that AMD was returning an error code, because OpenSSL was failing to generate a key, not generating a bad key?

Why would OpenSSL fail visibly if the API was returning success but with non-random data?

https://bugzilla.redhat.com/show_bug.cgi?id=1150286

Re:Some AMD CPU's RDRAND might not return random data after ... by int_19h on Wednesday May 08, 2019 @11:31PM (#19865129)
If you look closely at one of the error messages, it says "too many iterations", in what looks like a random generator. I wonder if at some point it has to iterate to get a number different from another one, and it just gets an endless stream of identical values?
Re:Some AMD CPU's RDRAND might not return random data after ... by zaroth on Wednesday May 08, 2019 @11:51PM (#19865212)
I can’t imagine the code is checking the returned value for uniqueness after seeing a SUCCESS code, and iterating in the hopes that becomes less true.

That would be quite something to read the comment on;

// Here we check to be sure the Earth is not flat

...

// Seeing that the Earth is indeed flat, we will iterate in this absurdity some more in the hopes it rounds out eventually

Re:Some AMD CPU's RDRAND might not return random data after ... by int_19h on Thursday May 09, 2019 @04:11PM (#19871914)
Suppose you need to generate several unique 32-bit IDs for something?
Re:Some AMD CPU's RDRAND might not return random data after ... by zaroth on Tuesday May 07, 2019 @11:56AM (#19850675)
Sounds like a bit of code which was hard to trigger the negative test and therefore the fallback failed to work properly.

Not sure how the kernel devs generally go about testing the “this virtually never happens” code paths without adding debug switches to every unhappy path.

Certainly I doubt they are using DI/IoC to wrap an interface to RDRAND which allows unit testing the failure modes.

At least the result is a failure to generate a key, not a compromised key.

Re:Some AMD CPU's RDRAND might not return random data after ... by loeg on Tuesday May 07, 2019 @06:39PM (#19854087)
> Sounds like a bit of code which was hard to trigger the negative test and therefore the fallback failed to work properly.

No; it turns out that's giving systemd too much credit (sadly). See [1].

The problem appears to be that RDRAND was signalling success, but producing a nonrandom value. This is bad and a violation of the specification.

Can't speak to Linux kernel development, and in this particular case, that isn't the problem.

The linked bug involves systemd using the world's worst random number generator. A security engineer goes into more detail on this twitter thread[1]: https://twitter.com/FiloSottile/status/1125840275346198529 (or unrolled: https://threadreaderapp.com/thread/1125840275346198529.html?... ).

> At least the result is a failure to generate a key, not a compromised key.

In fact, the result is a compromised key -- the bug report is due to colliding "globally unique" identifies generated through a flawed random gathering process.

[dead]
Re:Some AMD CPU's RDRAND might not return random data after ... by JdeBP on Wednesday May 08, 2019 @08:01AM (#19858003)
Filippo Valsorda said nothing about keys. Xe did not mention them at all.
Re:Some AMD CPU's RDRAND might not return random data after ... by zaroth on Wednesday May 08, 2019 @03:49PM (#19862230)
The linked bug report showed errors using OpenSSL to generate keys after resume on an AMD platform. It seemed to indicate RDRAND returning an error code instead of entropy.

Sorry for any confusion.

Re:Some AMD CPU's RDRAND might not return random data after ... by nitrogen on Tuesday May 07, 2019 @09:55PM (#19855250)
UUIDs and hash table keys are probably what they meant by "keys".
Re:Some AMD CPU's RDRAND might not return random data after ... by marshray on Tuesday May 07, 2019 @03:43PM (#19852778)
The 'edit-compile-run-debug' cycle is so expensive, chip design is all about simulation.

Chip vendors, and the tools they use to design them, actually do a significant amount of work for error cases. This is important not just for correctness, but for production yield, reliability, temperature and radiation hardness, etc. As chips get larger and more dense this becomes more and more important.

Single Event Upset (where one bit flips) is an example of the type of error. https://en.wikipedia.org/wiki/Single_event_upset

Re:Some AMD CPU's RDRAND might not return random data after ... by SolarNet on Tuesday May 07, 2019 @01:22PM (#19851472)
Virtual machines perhaps.
Re:Some AMD CPU's RDRAND might not return random data after ... by iforgotpassword on Tuesday May 07, 2019 @01:39PM (#19851642)
To be fair from that thread I can't infer whether they check if the call succeeded. It might very well be it returns success but still yields -1.
Re:Some AMD CPU's RDRAND might not return random data after ... by baq on Tuesday May 07, 2019 @11:47AM (#19850582)
i don't see any reason to not xor rdrand output with a prng if rdrand is available. please enlighten us why you think otherwise as i'm really interested in assumptions that lead to this conclusion.
Re:Some AMD CPU's RDRAND might not return random data after ... by lvh on Tuesday May 07, 2019 @11:51AM (#19850615)
Do you mean if a PRNG is available? Because the answer is obvious if RDRAND is available: you don't do that because sometimes it fails, failure is almost always catastrophic but sublte, and CSRPNGs are not a bottleneck in almost all cases.
Re:Some AMD CPU's RDRAND might not return random data after ... by amluto on Tuesday May 07, 2019 @12:11PM (#19850816)
RDRAND has major benefits over any CSPRNG: there is no software-visible state that could possibly leak. With attacks like Spectre, there’s always a concern that your CSPRNG secrets could be leaked.
Re:Some AMD CPU's RDRAND might not return random data after ... by lvh on Tuesday May 07, 2019 @03:59PM (#19852913)
The scheme we’re discussing XORs the two at the end, so that flaw doesn’t apply. Also: empirically, “kernel leaks CSPRNG” state does not seem to be as much of a problem as “userspace is convinced it knows better than urandom/getrandom”.
Re:Some AMD CPU's RDRAND might not return random data after ... by kzrdude on Tuesday May 07, 2019 @01:08PM (#19851337)
So - are they not checking for error in this case, and using a value anyway?
Re:Some AMD CPU's RDRAND might not return random data after ... by Xylakant on Tuesday May 07, 2019 @03:00PM (#19852375)
They are checking for an error and there is none, but the value returned is bogus (always the same, causing collisions).