News for hackers. Stuff that matters.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by gruez on Monday January 11, 2021 @02:01PM (#25734318)
Given that rdrand is so flakey across systems, is there a reason why systemd even bothers using it? The comments suggest it's only used to generate uuids, which makes me think it's not performance sensitive code. If that's the case why increase code complexity and expose yourself to hardware flakiness just to save a few miliseconds?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by stefan_ on Monday January 11, 2021 @02:22PM (#25734756)
It's really ridiculous of AMD to keep fucking this up, even if the backdoor thing never stuck for RDRAND, the fact that one CPU vendor can't manage to make the thing not return identical values many many times over sure might.

Similar story for systemd of course, nobody would expect them to learn their lesson. How nice of an init system to keep your system dead because it apparently needs CPRNG generated job ids of all things.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by temac on Monday January 11, 2021 @03:22PM (#25736002)
Given this is broken over and over again in successives AMD chips, this is actually a little bit likely to be a backdoor. People will e.g. generate keys with broken rdrand, and AMD will later fix it with plausible deniability, just saying "oops, sorry, it was just our silly usual mistake, and we don't even promise we won't do it again, lol!". In the meantime the NSA will enjoy the resulting compromises. And well, even if it was just the same silly mistake made over and over again, the NSA is likely to still enjoy the results?

So it does not really matter if it was intentional or not: regardless of the root cause of this bug, it should now be considered that rdrand should never be trusted (unless you truly don't care that your systems risk to randomly break or you risk to randomly generate compromised keys) and its mere usage (except maybe indirectly in mitigated ways designed by experts and audited for years) considered a very likely security vulnerability.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by altfredd on Monday January 11, 2021 @02:40PM (#25735116)
It seems, that many RedHat developers have rather unique world views.

When PulseAudio introduces random crackles and scratches in sound output, they claim, that I have a misbehaving sound card. It does not "misbehave", when I use the same applications with ALSA, but whatever.

When rdrand fails to produce high-quality entropy — again and again, over and over — Poettering complains about buggy CPUs.

I hope, that this particular group never ends up working on network hardware.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by Avamander on Monday January 11, 2021 @02:53PM (#25735403)
> It does not "misbehave", when I use the same applications with ALSA, but whatever.

I mean RDRAND is a great example here, if you never use it, you never encounter these bugs. It's not impossible that PulseAudio tries to play higher quality audio or simply uses the device differently.

> I hope, that this particular group never ends up working on network hardware.

I'd kinda love it, probably quite a few fun hardware bugs will be found.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by vetinari on Monday January 11, 2021 @04:33PM (#25737514)
> It's not impossible that PulseAudio tries to play higher quality audio or simply uses the device differently.

Pulseaudio mixes sound from several applications, unlike Alsa. Alsa just configures your soundcard for that one stream, Pulseaudio has no such luxury.

In order to mix relatively small buffers (because latency), it needs to do timing. If your soundcard has problem with timing (and many do!), you will get crackling. The good news is, that the problem with timing can be only at specific frequencies; in the past, I had a computer with Nvidia Ion and it did this with 44,1kHz audio. With 48kHz, everything was OK. So fixing the output at 48kHz by forcing Pulse to mix at this frequency fixed the crackling.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by frankling_ on Monday January 11, 2021 @08:07PM (#25740893)
Alsa has had software mixing via dmix since 2003.

https://www.alsa-project.org/wiki/Main_Page_News

Re:RDRAND on AMD Ryzen 9 5900X is flakey by vetinari on Monday January 11, 2021 @09:00PM (#25741312)
Yes, and it was off by default, because it had even bigger problems than PA.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by frankling_ on Tuesday January 12, 2021 @06:40AM (#25745524)
I'll skip the usual list of personal anecdotes about PA failing in surprising ways I've never seen in 15+ years of using Alsa, but I will say that since a few applications have started depending on it, "apt-get purge pulseaudio" seems to always be in my shell history.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by vetinari on Tuesday January 12, 2021 @07:02AM (#25745711)
You know, that by doing that, you are trading short term gain for long term pain?

Dmix for alsa was buggy, because just like PA, it didn't know about quirks of the hardware out in the field. And it stayed buggy, because nobody used it in return. Yes, PA was forced on users, but in the result the quirks were found, implemented and today, we all are better off. I didn't have any problem with PA since 2012 or so, but quite enjoyed the features it brought to the desktop.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by Dylan16807 on Monday January 11, 2021 @03:02PM (#25735587)
I'm reminded of this story about hidden network card bugs. Working in a bunch of tests doesn't mean something is correct, especially when it's complex.

https://devblogs.microsoft.com/oldnewthing/20050512-48/?p=35...

Re:RDRAND on AMD Ryzen 9 5900X is flakey by LukeShu on Monday January 11, 2021 @03:20PM (#25735957)
The source code has a lengthy comment explaining why.

https://github.com/systemd/systemd/blob/bcac754d66374782a85a...

Re:RDRAND on AMD Ryzen 9 5900X is flakey by robocat on Monday January 11, 2021 @04:19PM (#25737220)

    int rdrand(unsigned long *ret) {
    /* So, you are a "security researcher", and you wonder why we bother with using raw RDRAND here,
         * instead of sticking to /dev/urandom or getrandom()?
         *
         * Here's why: early boot. On Linux, during early boot the random pool that backs /dev/urandom and
         * getrandom() is generally not initialized yet. It is very common that initialization of the random
         * pool takes a longer time (up to many minutes), in particular on embedded devices that have no
         * explicit hardware random generator, as well as in virtualized environments such as major cloud
         * installations that do not provide virtio-rng or a similar mechanism.
         *
         * In such an environment using getrandom() synchronously means we'd block the entire system boot-up
         * until the pool is initialized, i.e. *very* long. Using getrandom() asynchronously (GRND_NONBLOCK)
         * would mean acquiring randomness during early boot would simply fail. Using /dev/urandom would mean
         * generating many kmsg log messages about our use of it before the random pool is properly
         * initialized. Neither of these outcomes is desirable.
         *
         * Thus, for very specific purposes we use RDRAND instead of either of these three options. RDRAND
         * provides us quickly and relatively reliably with random values, without having to delay boot,
         * without triggering warning messages in kmsg.
         *
         * Note that we use RDRAND only under very specific circumstances, when the requirements on the
         * quality of the returned entropy permit it. Specifically, here are some cases where we *do* use
         * RDRAND:
         *
         *         • UUID generation: UUIDs are supposed to be universally unique but are not cryptographic
         *           key material. The quality and trust level of RDRAND should hence be OK: UUIDs should be
         *           generated in a way that is reliably unique, but they do not require ultimate trust into
         *           the entropy generator. systemd generates a number of UUIDs during early boot, including
         *           'invocation IDs' for every unit spawned that identify the specific invocation of the
         *           service globally, and a number of others. Other alternatives for generating these UUIDs
         *           have been considered, but don't really work: for example, hashing uuids from a local
         *           system identifier combined with a counter falls flat because during early boot disk
         *           storage is not yet available (think: initrd) and thus a system-specific ID cannot be
         *           stored or retrieved yet.
         *
         *         • Hash table seed generation: systemd uses many hash tables internally. Hash tables are
         *           generally assumed to have O(1) access complexity, but can deteriorate to prohibitive
         *           O(n) access complexity if an attacker manages to trigger a large number of hash
         *           collisions. Thus, systemd (as any software employing hash tables should) uses seeded
         *           hash functions for its hash tables, with a seed generated randomly. The hash tables
         *           systemd employs watch the fill level closely and reseed if necessary. This allows use of
         *           a low quality RNG initially, as long as it improves should a hash table be under attack:
         *           the attacker after all needs to trigger many collisions to exploit it for the purpose
         *           of DoS, but if doing so improves the seed the attack surface is reduced as the attack
         *           takes place.
         *
         * Some cases where we do NOT use RDRAND are:
         *
         *         • Generation of cryptographic key material 
         *
         *         • Generation of cryptographic salt values 
         *
         * This function returns:
         *
         *         -EOPNOTSUPP → RDRAND is not available on this system 
         *         -EAGAIN     → The operation failed this time, but is likely to work if you try again a few
         *                       times 
         *         -EUCLEAN    → We got some random value, but it looked strange, so we refused using it.
         *                       This failure might or might not be temporary. 
         */
Re:RDRAND on AMD Ryzen 9 5900X is flakey by rasz on Tuesday January 12, 2021 @05:49AM (#25745067)
Yes, the famous 'I want my Random number be even more random by adding more random numbers to it, otherwise its no good.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by LukeShu on Tuesday January 12, 2021 @11:49AM (#25749504)
That's not what's going on here. You're referring to the braindead behavior that `/dev/random` can block because it thinks its entropy pool has been depleted, which is of course dumb because once the pool is sufficiently full it can't be emptied. What's going on here is the scenario where the pool genuinely is empty because it hasn't been filled yet. This can only happen at early boot, but is a genuine thing that happens; unlike it becoming empty later.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by gruez on Monday January 11, 2021 @04:31PM (#25737456)
But what happens on systems that don't have rdrand? Surely there is a fallback. Why isn't the fallback used in all cases, given how flakey rdrand is?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by rcxdude on Monday January 11, 2021 @04:49PM (#25737793)
It falls back to /dev/urandom, which will cause the kernel bitterly complain by spamming log messages while the entropy pool hasn't been seeded.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by LukeShu on Monday January 11, 2021 @06:02PM (#25739140)
If I'm reading the source right, it actually falls back to a blocking `getrandom` followed by /dev/urandom; so actually instead of spamming the logs about "entropy pool hasn't been seeded", it will block until it is seeded.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by segfaultbuserr on Monday January 11, 2021 @06:55PM (#25740072)
It'll also block the system from booting for as long as a few minutes in the absence of user input.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by secondcoming on Monday January 11, 2021 @04:51PM (#25737825)
Since they only use it for UUID generation, couldn't they use rdrand() to seed a PGC pseudo-RNG?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tadfisher on Monday January 11, 2021 @02:58PM (#25735506)
It's not systemd's job to fix hardware bugs, it's the kernel's (or AMD's). The fix for the last time this happened was to mask the offending CPU IDs in the kernel's RNG from using RDRAND. systemd did have a temporary hack in place for their direct RDRAND implementation, but this current bug isn't the same (not just emitting 0 like last time, but eventually emitting duplicate values in pairs).
Re:RDRAND on AMD Ryzen 9 5900X is flakey by ginko on Monday January 11, 2021 @03:19PM (#25735945)
Even so, systemd should be able to deal with name collisions even with numbers coming from a true RNG. That causing errors is a design issue, IMO.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tadfisher on Monday January 11, 2021 @03:40PM (#25736390)
That would be a non-deterministic failure case scaling to O(n) in both space and time. But it's not just UUIDs, it's also required for seeding systemd's internal hash tables, which would degrade from O(1) lookups to O(n) should an attacker exploit known RNG flaws.

So, a PRNG with a semi-decent (not perfect) entropy pool is required at boot time, and systemd needs to run in environments where seeding that pool in software could take on the order of minutes. This is why RDRAND is used to seed the pool during boot.

https://github.com/systemd/systemd/blob/61bd7d1ed595a98e5fbf...

Re:RDRAND on AMD Ryzen 9 5900X is flakey by aidenn0 on Monday January 11, 2021 @05:22PM (#25738335)
1. UUIDs are stored somewhere so there's already O(n) space in use. Checking for collisions is only O(log n) in time.

2. Use a tree instead of a hash-table; or just use RDRAND and hope you aren't presented with malicious inputs.

The comment in the code[1] about RDRAND being sufficient for the use-case of UUIDs is empirically false. To continue to rely upon it is to insist that the rest of the world conform to your beliefs, rather than to adjust your beliefs to match the rest of the world.

1: https://github.com/systemd/systemd/blob/bcac754d66374782a85a...

Re:RDRAND on AMD Ryzen 9 5900X is flakey by tadfisher on Monday January 11, 2021 @05:48PM (#25738817)
> The comment in the code[1] about RDRAND being sufficient for the use-case of UUIDs is empirically false.

Ipse dixit. Can you provide an explanation?

Re:RDRAND on AMD Ryzen 9 5900X is flakey by aidenn0 on Monday January 11, 2021 @05:53PM (#25738935)
1. TFA

2. https://arstechnica.com/gadgets/2019/10/how-a-months-old-amd...

3. https://linuxreviews.org/RDRAND_stops_returning_random_value...

4. There are also comments elsewhere on this page that older Intel RDRAND implementations had similar issues, but they did not cite their source.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by johncolanduoni on Monday January 11, 2021 @03:38PM (#25736351)
Most cryptographic constructs you feed CSPRNG data into break spectacularly if they receive colliding data so I guess they all have design issues too. Including the TLS connection you’re typing your comment through.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tremon on Monday January 11, 2021 @05:36PM (#25738590)
But it becomes systemd's job to fix/compensate for hardware bugs if they explicitly access the hardware directly instead of going through the kernel, no?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by LukeShu on Monday January 11, 2021 @09:33PM (#25741518)
They do go through the kernel; it asks the kernel "can I use rdrand", and the kernel says "yep, go ahead, it works on this CPU". If that's not true, and it doesn't work on the CPU, then it's the kernel's fault for lying and saying that it does.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by klmadfejno on Monday January 11, 2021 @03:04PM (#25735617)
That doesn't seem to answer the question of why use it
Re:RDRAND on AMD Ryzen 9 5900X is flakey by numpad0 on Monday January 11, 2021 @03:23PM (#25736024)
It generally makes more sense to trust CPU specifications and utilize it fully, than to assume everything is tampered with and only ever use `mov`
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tadfisher on Monday January 11, 2021 @03:22PM (#25735995)
If they don't use it, the kernel does in order to initialize the entropy pool, which will also result in broken boots. To work around historically flaky kernel implementations, systemd calls RDRAND directly if it detects it needs to with a heuristic. This is why the fix for the current issue is to set both 'nordrand' and 'SYSTEMD_RDRAND=0'.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tedunangst on Monday January 11, 2021 @04:43PM (#25737696)
What happened to it's not systemd's job to fix kernel bugs?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tadfisher on Monday January 11, 2021 @05:36PM (#25738585)
I didn't type that, so I'm not sure what you're referring to. systemd is fundamentally tied to Linux and thus needs to implement workarounds from time-to-time when kernel facilities are lacking. This is complicated by the requirement that systemd continue working on older Linux versions.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by effie on Monday January 11, 2021 @06:21PM (#25739495)
I think it is systemd's job to make sure it works for its users, even though that requires working around HW bugs. If RDRAND is so problematic and can be not used, why use it at all? Just abstain from using it, simplify the logic and solve this class of issues once and for all.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by garaetjjte on Monday January 11, 2021 @03:02PM (#25735586)
As much as I don't like systemd this probably was reasonable decision back at the time. systemd needs entropy for generating some random identifiers during early boot. Trying to read it from kernel random facilities might block infinitely until kernel 5.4. Before that pulling entropy from RDRAND might not be that unreasonable decision, nowadays it probably should just call getrandom().
Re:RDRAND on AMD Ryzen 9 5900X is flakey by tremon on Monday January 11, 2021 @05:40PM (#25738645)
But why does systemd need random identifiers during early boot? I can understand the need for seeding a hash table (but even there, they already admit that the code can re-seed at any time), but I don't see why a boot program should rely on random id generation in the first place.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by zuzun on Monday January 11, 2021 @03:42PM (#25736420)
> just to save a few miliseconds?

RDRAND is rather slow, especially with the SRBDS microcode update. One instruction takes 1,200 ns on my system, that's 6.6 MB/s. A software implementation of a CSPRNG will do hundreds of MB/s, the general purpose PRNGs do several GB/s.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by okl on Monday January 11, 2021 @02:07PM (#25734437)
Possibly because it helps to bootstrap the entropy pool, see for example these ramblings on the topic: https://daniel-lange.com/archives/152-Openssh-taking-minutes...
Re:RDRAND on AMD Ryzen 9 5900X is flakey by espadrine on Monday January 11, 2021 @02:26PM (#25734836)
Isn’t that an even bigger problem, though, if Linux’ entropy pool gets polluted by an inentropic source that still increments its entropy counter?

I recall discussions to maybe rely on something like jitter entropy when the pool is empty and getentropy() is called.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by altfredd on Monday January 11, 2021 @03:06PM (#25735656)
Linux entropy pool is designed to accept and mix different low-quality entropy sources and has explicit workarounds for problems like these.

Systemd is literally the only software, that has this problem. I am not aware of any other software, that uses rdrand and expects high-quality cryptography-grade randomness. Precisely, because is does not work. Intel CPUs used to have very similar issues with rdrand and so did AMD. Furthermore, CPU implementation of rdrand is a very attractive targets for state backdoors, so most sensible developers either follow the "GNUPG way" (ask for randomness from user) or simply read from /dev/random.

The rdrand instruction is great for games, because it allows to make white noise without complex algorithms and system call overhead. It is also handy for few situations, like interrupt handlers, when you needs to create some semi-random value without using stack space or calling into outside code. Unfortunately, when it was introduced, rdrand was documented to generate "cryptographically strong random numbers" (did Intel developers ever knew, what that means?) Of course, most actual cryptography experts didn't buy into that. As a consequence, and because multi-platform software needed to have it's own RNG anyway, the instruction remained largely unused for actual cryptography. Unused = untested and sometimes broken. If I were in systemd developer's place, I would not hinge bootability of my systems on something like that.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by tadfisher on Monday January 11, 2021 @03:58PM (#25736798)
> Systemd is literally the only software, that has this problem. I am not aware of any other software, that uses rdrand and expects high-quality cryptography-grade randomness.

Please seek out and understand the reasons behind calling RDRAND in systemd before making statements like these. "High-quality crytography-grade randomness" is explicitly not required for the purposes of the PRNG at boot-time, which include UUID generation and seeding hash tables.

https://github.com/systemd/systemd/blob/61bd7d1ed595a98e5fbf...

Re:RDRAND on AMD Ryzen 9 5900X is flakey by tremon on Monday January 11, 2021 @05:44PM (#25738723)
Why would the boot process need to generate UUID's? And even if it does, why would it need truly random UUIDv4s instead of simple UUIDv1s?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by LukeShu on Monday January 11, 2021 @09:44PM (#25741597)
UUIDv1s (RFC 4122 §4.2.1) also rely on several things that are even less likely to be available at early-boot:

- The clock might not be initialized; the justification for using rdrand specifically calls out embedded systems; embedded systems are also likely to have clocks that reset to some date every boot and get fixes as part of the boot process that happens later.

- The "node ID" (nominally, a MAC address) udev has not started yet and therefore has not initialized the network cards yet (in fact, if you configure it to randomize your MAC address (for privacy), the random_bytes() routine being discussed is the one that it will use to generate the MAC!) The filesystem hasn't yet been mounted, it can't use /etc/machine-id or anything like that either.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by Dylan16807 on Monday January 11, 2021 @03:44PM (#25736476)
> The rdrand instruction is great for games, because it allows to make white noise without complex algorithms and system call overhead.

Eh. You're looking at hundreds of cycles per use. That makes it slower than a secure software RNG, let alone an insecure one.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by jcelerier on Monday January 11, 2021 @04:26PM (#25737384)
Right ! For games if it's for e.g. texture noise or things like that you shouldn't need more than a couple xors and shifts
Re:RDRAND on AMD Ryzen 9 5900X is flakey by ficklepickle on Monday January 11, 2021 @03:20PM (#25735967)
It's an early boot problem. If they tried to use the kernel facilities it would block, making boot take much longer. Fixed in recent kernel versions.

I know it's in vogue to rip on systemd, but let's at least try to be fair.

Re:RDRAND on AMD Ryzen 9 5900X is flakey by freeone3000 on Monday January 11, 2021 @03:50PM (#25736637)
Somehow sysv init never ran into this issue. Maybe it's okay to let the kernel seed its entropy pool before initializing your hash table.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by Foxboron on Monday January 11, 2021 @04:22PM (#25737292)
I don't think sysvinit made use of hashtables, and if they did they would probably hit the same snag.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by aidenn0 on Monday January 11, 2021 @05:25PM (#25738386)
sysvinit (or rather RC systems often built on top of it) tended to use trees (most often the filesystem). Unlike hash-tables, trees don't need randomness to guarantee asymptotic behavior.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by garaetjjte on Monday January 11, 2021 @02:56PM (#25735469)
>on something like jitter entropy when the pool is empty and getentropy() is called

This ended up being implemented in 5.4 kernel: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

Re:RDRAND on AMD Ryzen 9 5900X is flakey by CJefferson on Tuesday January 12, 2021 @03:42AM (#25743994)
When it comes to random seeding, I've always thought the best option would be to use every source available, and hope that at least one is high quality. If we combine:

* RDRAND * Seed from previous boot * Jitter * Result of every sensor (for example temperature) attached to the machine * Seed from hypervisor (if we are in a VM) * Time & Date * Any information about the physical computer we are on (attached hardware)

Re:RDRAND on AMD Ryzen 9 5900X is flakey by recursive on Monday January 11, 2021 @02:08PM (#25734452)
Who's spending multiple milliseconds generating uuids? I'm sure it happens somewhere, somehow, but that does not seem like a common occurrence.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by AshamedCaptain on Monday January 11, 2021 @03:00PM (#25735556)
And why do you even need globally UUIDs here? What's wrong with a plain old sequence counter or the like?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by stragies on Monday January 11, 2021 @03:26PM (#25736098)
Among others is that predictability of behavior of systems makes analysis and/or attack easier. Also "plain old sequence counters" in clusters of (heterogeneous) hardware makes distributing (floating) tasks more challenging. There are a bunch of other reasons.
Re:RDRAND on AMD Ryzen 9 5900X is flakey by effie on Monday January 11, 2021 @05:29PM (#25738460)
How is using UUIDs making software more predictable than using sequence numbers?
Re:RDRAND on AMD Ryzen 9 5900X is flakey by stragies on Tuesday January 12, 2021 @02:54AM (#25743655)
the opposite: UUIDs make things less predictable. And in many situations this is very good.