Repository navigation
Closed
Labels
Description
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.
Reacted by NotAFile, Joe Richey, Germano Massullo, Jeffrey Walton, iczero, Guilhem Saurel and Brian Smith
Reacted by Victor, Alexander-- and AlphaHot
Reacted by Pavlo Rudy, nat and Marvin
Reacted by nat
Activity
poettering commentedon Jan 11, 2021
this smells as if your CPU has a borked RDRAND implementation.
i.e. a story like this one:
https://arstechnica.com/gadgets/2019/10/how-a-months-old-amd-microcode-bug-destroyed-my-weekend/
poettering commentedon Jan 11, 2021
can you reboot reliably if you add "nordrand" to the kernel cmdine? See #11810
asahaf commentedon Jan 11, 2021
That actually what I suspected when I started googling. I've downloaded the small program in linked article and execute it. Here is output:
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
asahaf commentedon Jan 11, 2021
here is the output with
nordrandargumentpoettering commentedon Jan 11, 2021
If you add
SYSTEMD_RDRAND=0to the kernel cmdline, does that change anything?asahaf commentedon Jan 11, 2021
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?
poettering commentedon Jan 11, 2021
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.
poettering commentedon Jan 11, 2021
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.
[-] Systemd fails to start services with error - Failed to set invocation ID for unit: File exists[/-][+]RDRAND on AMD Ryzen 9 5900X is flakey[/+]asahaf commentedon Jan 11, 2021
Thank you very much, do I still need
nordrandargument for the kernel too, in addition toSYSTEMD_RDRAND=0till the vendor fix it with microcode?poettering commentedon Jan 11, 2021
nordrandturns off RDRAND use by the kernel, i.e. means the kernel won't use it to seed the kernel pool.SYSTEMD_RDRAND=0turns 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.
asahaf commentedon Jan 11, 2021
you're right, after I've generated many randoms, I was able to get collisions.
poettering commentedon Jan 11, 2021
@asahaf looks like systemd is not at fault.
I figure:
And we can close this here I guess, we can't do much about this from our side.
poettering commentedon Jan 11, 2021
/cc @tlendacky (the author of c49a0a80137c7ca7d6ced4c812c9e07a949f6f24)
63 remaining items
bearoso commentedon Jan 13, 2021
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.
asahaf commentedon Jan 13, 2021
I see
asahaf commentedon Jan 13, 2021
@bearoso I've just installed F31 from Gigabyte website, replacing F31b and it seems the update solved the issue.
poettering commentedon Jan 13, 2021
OK, let's close this here then, as it's a apparently a confirmed issue between CPU + firmware.
asahaf commentedon Jan 14, 2021
@poettering Thanks
bryanyork commentedon Jan 25, 2021
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.
bryanyork commentedon Jan 28, 2021
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.
poettering commentedon Jan 28, 2021
@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?
bryanyork commentedon Jan 28, 2021
@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.
briansmith commentedon Jan 28, 2021
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.
edwintorok commentedon Jan 28, 2021
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:
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.
edwintorok commentedon Jan 28, 2021
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.
poettering commentedon Jan 28, 2021
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.