Skip to content

RDRAND on AMD Ryzen 9 5900X is flakey #18184

Closed

Description

@asahaf

systemd version the issue has been seen with

247.2-1

Used distribution

Arch Linux

Linux kernel version used (uname -a)

5.10.5-arch1-1

CPU architecture issue was seen on

AMD Ryzen 9 5900X

Expected behaviour you didn't see

Start systemd services

Unexpected behaviour you saw

Starting services sometimes fails with message: Failed to set invocation ID for unit: File exists

Steps to reproduce the problem

Starting up the system and login (sometimes, the os doesn't even boot)

Additional Information
CPU: AMD Ryzen 9 5900X
Microcode update image (amd-ucode) version: 20201218.646f159-1
Motherboard: X570 i Aorus Pro Wifi
BIOS/Firmware Version: F31b (10/28/2020)
Arch Kernel Version: 5.10.5-arch1-1
Systemd Version: 247.2-1

Logs

Jan 08 21:47:40 archlinux systemd[1]: dev-ttyS27.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: sys-devices-platform-serial8250-tty-ttyS27.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: dev-ttyS29.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: sys-devices-platform-serial8250-tty-ttyS29.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: dev-ttyS28.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: sys-devices-platform-serial8250-tty-ttyS28.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: dev-ttyS3.device: Failed to set invocation ID for unit: File exists
Jan 08 21:47:40 archlinux systemd[1]: dev-ttyS31.device: Failed to set invocation ID for unit: File exists
Jan 08 21:49:03 office01 systemd[1]: sys-kernel-tracing.mount: Failed to set invocation ID for unit: File exists
Jan 08 21:49:03 office01 systemd[1]: Failed to mount Kernel Trace File System.

Activity

  1. poettering commented on Jan 11, 2021

    @poettering
    Member
  2. poettering commented on Jan 11, 2021

    @poettering
    Member

    can you reboot reliably if you add "nordrand" to the kernel cmdine? See #11810

  3. asahaf commented on Jan 11, 2021

    @asahaf
    Author

    That actually what I suspected when I started googling. I've downloaded the small program in linked article and execute it. Here is output:

    ❯ ./rdrand-test/amd-rdrand-bug
    Your RDRAND() does not have the AMD bug.
    
    ❯ ./rdrand-test/test-rdrand
    RDRAND() = 0x757b61ec
    RDRAND() = 0x4c0527be
    RDRAND() = 0xe4ccb42a
    RDRAND() = 0xc54d5506
    RDRAND() = 0x7c414b9e
    RDRAND() = 0x5075cb07
    RDRAND() = 0x5cd99e55
    RDRAND() = 0xc6ca8a67
    RDRAND() = 0x844013d9
    RDRAND() = 0x927b689d
    RDRAND() = 0xd344ddfc
    RDRAND() = 0x7809d123
    RDRAND() = 0x3481b240
    RDRAND() = 0xed6269b7
    RDRAND() = 0x5909acd7
    RDRAND() = 0x70c4c118
    RDRAND() = 0x240d6150
    RDRAND() = 0x7532c2b5
    RDRAND() = 0xe86bddc4
    RDRAND() = 0xf40c31fa
    

    Now I got confused. I'm not sure if that issue is because of a broken CPU rdrand implementation

    I'll try the nordrand argument, and get back to you

  4. asahaf commented on Jan 11, 2021

    @asahaf
    Author

    here is the output with nordrand argument

    -- Journal begins at Wed 2021-01-06 21:15:50 +03, ends at Mon 2021-01-11 19:59:23 +03. --
    Jan 11 19:59:18 office01 systemd[1]: basic.target: Failed to set invocation ID for unit: File exists
    Jan 11 19:59:18 office01 systemd[1]: Failed to start Basic System.
    ░░ Subject: A start job for unit basic.target has failed
    ░░ Defined-By: systemd
    ░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
    ░░
    ░░ A start job for unit basic.target has finished with a failure.
    ░░
    ░░ The job identifier is 116 and the job result is failed.
    Jan 11 19:59:18 office01 systemd[1]: dbus.service: Failed to set invocation ID for unit: File exists
    Jan 11 19:59:18 office01 systemd[1]: Failed to start D-Bus System Message Bus.
    ░░ Subject: A start job for unit dbus.service has failed
    ░░ Defined-By: systemd
    ░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
    ░░
    ░░ A start job for unit dbus.service has finished with a failure.
    ░░
    ░░ The job identifier is 209 and the job result is failed.
    
  5. poettering commented on Jan 11, 2021

    @poettering
    Member

    If you add SYSTEMD_RDRAND=0 to the kernel cmdline, does that change anything?

  6. asahaf commented on Jan 11, 2021

    @asahaf
    Author

    This argument seems solved the issue. This systemd issue used to happen 7/10 of the times when I reboot my machine. Now after applying this argument (SYSTEMD_RDRAND=0), I rebooted my machine 10 times with no issues.

    Does this argument disables the relying on the CPU for generating random seed? and why is it sometimes, without the argument, I get lucky to boot the system without this issue?

  7. poettering commented on Jan 11, 2021

    @poettering
    Member

    Smells as if your RDRAND on your CPU is flaky, and doesn't generate properly random stuff, but frequently the same values. I'd report that to your CPU vendor. Like all RDRAND issues this is security sensitive as it can be.... In particular as most distros now default to seeding the kernel entropy pool with RDRAND.

  8. poettering commented on Jan 11, 2021

    @poettering
    Member

    Does this argument disables the relying on the CPU for generating random seed? and why is it sometimes, without the argument, I get lucky to boot the system without this issue?

    I can't answer that, it seems the RNG in the CPU is reliable and sometimes works and sometimes doesn't.

    systemd uses RDRAND to generate UUIDs only, nothing else, and exactly as suggested by the whitepapers. if this generates non-unique UUIDs that so easily collide then the RNG is just rubbish.

  9. changed the title [-] Systemd fails to start services with error - Failed to set invocation ID for unit: File exists[/-] [+]RDRAND on AMD Ryzen 9 5900X is flakey[/+] on Jan 11, 2021
  10. asahaf commented on Jan 11, 2021

    @asahaf
    Author

    Thank you very much, do I still need nordrand argument for the kernel too, in addition to SYSTEMD_RDRAND=0 till the vendor fix it with microcode?

  11. poettering commented on Jan 11, 2021

    @poettering
    Member

    nordrand turns off RDRAND use by the kernel, i.e. means the kernel won't use it to seed the kernel pool.

    SYSTEMD_RDRAND=0 turns off RDRAND use by systemd, i.e. we won't generate UUIDs with it. (it won't use it for crypto keys anyway)

    So the two switches matter, but of course there's a bunch of other userspace sw that might use RDRAND, where you want to turn it off, but there's no common way to do that I was aware of.

  12. asahaf commented on Jan 11, 2021

    @asahaf
    Author

    you're right, after I've generated many randoms, I was able to get collisions.

    RDRAND() = 0x0081da17
    RDRAND() = 0x0081da17
    RDRAND() = 0x0178d2ea
    RDRAND() = 0x0178d2ea
    RDRAND() = 0x02a91db5
    RDRAND() = 0x02a91db5
    RDRAND() = 0x06c4385b
    RDRAND() = 0x06c4385b
    RDRAND() = 0x095d1bf8
    RDRAND() = 0x095d1bf8
    RDRAND() = 0x0990b335
    RDRAND() = 0x0990b335
    RDRAND() = 0x0ab033e4
    RDRAND() = 0x0ab033e4
    RDRAND() = 0x0ac21fae
    RDRAND() = 0x0ac21fae
    RDRAND() = 0x0d39390b
    RDRAND() = 0x0d39390b
    RDRAND() = 0x0df2f5ce
    RDRAND() = 0x0df2f5ce
    RDRAND() = 0x109e5c8a
    RDRAND() = 0x109e5c8a
    
  13. poettering commented on Jan 11, 2021

    @poettering
    Member

    @asahaf looks like systemd is not at fault.

    I figure:

    1. someone who cares needs to report this to AMD
    2. kernel should probably mask RDRAND on these CPUs too, i.e. follow-up for kernel commit c49a0a80137c7ca7d6ced4c812c9e07a949f6f24. someone who cares should ping relevant kernel folks about this
    3. Someone who cares should ask for a CVE against the AMD CPUs.

    And we can close this here I guess, we can't do much about this from our side.

  14. poettering commented on Jan 11, 2021

    @poettering
    Member

    /cc @tlendacky (the author of c49a0a80137c7ca7d6ced4c812c9e07a949f6f24)

  15. 63 remaining items

  16. bearoso commented on Jan 13, 2021

    @bearoso

    Gigabyte labels unstable bios versions with letters. So F31b is the second test release for F31, and F31 with no letter is the final, much more recent, version.

  17. asahaf commented on Jan 13, 2021

    @asahaf
    Author

    I see

  18. asahaf commented on Jan 13, 2021

    @asahaf
    Author

    @bearoso I've just installed F31 from Gigabyte website, replacing F31b and it seems the update solved the issue.

  19. poettering commented on Jan 13, 2021

    @poettering
    Member

    OK, let's close this here then, as it's a apparently a confirmed issue between CPU + firmware.

  20. asahaf commented on Jan 14, 2021

    @asahaf
    Author
  21. bryanyork commented on Jan 25, 2021

    @bryanyork

    Just adding another datapoint here. I'm also affected using an ASRockRack X570D4U-2L2T motherboard using the latest P1.30 BIOS with the 1.1.0.0 AGESA version. I've contacted both ASRock and AMD regarding this and will report back.

  22. bryanyork commented on Jan 28, 2021

    @bryanyork

    So I wondered why we couldn't combine entropy of ioctl and combine with RDRAND to solve this flakeyness. Looks like someone has already done this with another RDRAND bug. I was able to replace out the random-seed service with their script. (After one small tweak to the script to support reading binary via stdin for python3: sys.stdin = sys.stdin.detach())
    https://bugzilla.redhat.com/show_bug.cgi?id=1572944#c46
    (Found via: http://daniel-lange.com/archives/152-Openssh-taking-minutes-to-become-available,-booting-takes-half-an-hour-...-because-your-server-waits-for-a-few-bytes-of-randomness.html)

    This leads to consistent boots with no errors.

    @poettering Is there any reason we can't implement this for systemd by default for now? I definitely want to know it's flakey, but if we can work around it for now while we wait for a fix, that would be helpful for users. ASRock Rack said they are looking into it, and I haven't heard back from AMD. I plan to submit a security bug to AMD via a more formal channel soon.

  23. poettering commented on Jan 28, 2021

    @poettering
    Member

    @bryanyork implement what? the kernel nowadays seeds the random pool from rdrand on its own, we don't need to do anything for that in userspace. But of course if your rdrand is borked the random pool will be filled with non-entropy the kernel migh misestimate the actual entropy of though, so what's the point? Not grokking what you are trying to say?

  24. bryanyork commented on Jan 28, 2021

    @bryanyork

    @poettering The above script solved the issue of UUID collisions for me while I wait for AMD/ASRock to provide a permanent fix. It solved it by pre-populating entropy through a combined source of ioctl and RDRAND which can be used reliably on boot. Since systemd queries directly from RDRAND, can we extend that to include entropy from ioctl, similar to the script I linked above? The goal is protect the user against these types of UUID collisions.

  25. briansmith commented on Jan 28, 2021

    @briansmith

    @bryanyork implement what? the kernel nowadays seeds the random pool from rdrand on its own, we don't need to do anything for that in userspace. But of course if your rdrand is borked the random pool will be filled with non-entropy the kernel migh misestimate the actual entropy of though, so what's the point? Not grokking what you are trying to say?

    Maybe I'm misunderstanding, but if the kernel is already using RDRAND and doing the right thing with it, then there would be no reason for systemd to be using RDRAND itself directly on that kernel. So then it would seem to make sense to limit the direct use of RDRAND to older kernels; i.e. start the migration of the responsibility of dealing with RDRAND bugs to the kernel and out of systemd.

  26. edwintorok commented on Jan 28, 2021

    @edwintorok

    Why do you need to use rdrand directly, and if you do why call it more than once? IIUC it is only used to generate UUIDs, not cryptographic material, so you just need to seed a (CS)PRNG based on sources that are available to you:

    • an optional machine specific seed
    • /dev/urandom
    • rdrand
    • boot counter
    • current time

    Once the PRNG is seeded it should ensure that it generates unique IDs on that machine, on that booted instance.
    The boot counter and current time should help to also make the generated IDs unique across boots. (unless it is a vrtual machine eternally reset to a snapshot and a bad clock)
    RDRAND if available, and working should counter the bad clock situation.
    The machine specific seed should ensure it generates unique IDs across machines (and to initialize that you can afford to wait until the kernel's random number generator has gathered enough entropy).

    This scheme would also be more robust against the failure of any of its components. In a cryptographic situation you wouldn't want to rely on weak elements like current time, or boot count, or a static seed, but for just generating some UUIDs they should help in practice.

  27. edwintorok commented on Jan 28, 2021

    @edwintorok

    A simple approach might be to generate a single (v4) UUID on boot seeded from available sources (rdrand, time, etc.).
    Then use that as a namespace UUID and generate v5 UUIDs based on a simple incrementing integer counter as the name. The initial UUID may not be perfect and may generate collisions, but at least not within the currently booted instance.

  28. poettering commented on Jan 28, 2021

    @poettering
    Member

    Folks, please read up first, before commenting, you are just adding more useless noise to a big mess. Which is really not helpful. For starters, read this:

    https://systemd.io/RANDOM_SEEDS

    It answers most of your questions and if you actually read it, should clean up some misunderstanding.

    TLDR, since i know people will probably no read the docs even if asked to do so and just going to add more super smart comments. We use RDRAND for basically uuids only, not for cryptographic material. we use it because we run during earliest boot, where the kernel random pool is very likely not initialized yet (only some distros seed kernel entropy pool from RDRAND) and we don't want to wait for that. if we'd hard rely on kernel entropy pool being initialized we'd block boot for a possibly long time (and we do, on systems without RDRAND and no other entropy source).

    And no, we are not going to maintain our own userspace RNG infrastructure, it's messy enough already. We'll use CPU provided, kernel provided or glibc provided RNG infra. There was talk of supporting arc4random in glibc. Once that materializes we are happy to switch systemd to use it, but probably still not for the uuid stuff, given that arc4random will be likely seeded by kernel entropy pool, which is exactly what we want to avoid, due to the boot time starvation issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions