summaryrefslogtreecommitdiffstats
path: root/src/udev/net
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-05-24 15:09:20 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-31 09:20:52 +0200
commit87cb1ab6765d9ad9482b882b26e45a683162a078 (patch)
treea2af6e58c9044f281828148da47a863f9b91ad0f /src/udev/net
parentMerge pull request #23533 from yuwata/portable-remove-drop-in-configs (diff)
downloadsystemd-87cb1ab6765d9ad9482b882b26e45a683162a078.tar.xz
systemd-87cb1ab6765d9ad9482b882b26e45a683162a078.zip
Simplify random number selection
We currently have a convoluted and complex selection of which random numbers to use. We can simplify this down to two functions that cover all of our use cases: 1) Randomness for crypto: this one needs to wait until the RNG is initialized. So it uses getrandom(0). If that's not available, it polls on /dev/random, and then reads from /dev/urandom. This function returns whether or not it was successful, as before. 2) Randomness for other things: this one uses getrandom(GRND_INSECURE). If it's not available it uses getrandom(GRND_NONBLOCK). And if that would block, then it falls back to /dev/urandom. And if /dev/urandom isn't available, it uses the fallback code. It never fails and doesn't return a value. These two cases match all the uses of randomness inside of systemd. I would prefer to make both of these return void, and get rid of the fallback code, and simply assert in the incredibly unlikely case that /dev/urandom doesn't exist. But Luca disagrees, so this commit attempts to instead keep case (1) returning a return value, which all the callers already check, and fix the fallback code in (2) to be less bad than before. For the less bad fallback code for (2), we now use auxval and some timestamps, together with various counters representing the invocation, hash it all together and provide the output. Provided that AT_RANDOM is secure, this construction is probably okay too, though notably it doesn't have any forward secrecy. Fortunately, it's only used by random_bytes() and not by crypto_random_bytes().
Diffstat (limited to 'src/udev/net')
-rw-r--r--src/udev/net/link-config.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 28c0e633a3..8fdb48f315 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -623,10 +623,7 @@ static int link_generate_new_hw_addr(Link *link, struct hw_addr_data *ret) {
/* We require genuine randomness here, since we want to make sure we won't collide with other
* systems booting up at the very same time. */
for (;;) {
- r = genuine_random_bytes(p, len, 0);
- if (r < 0)
- return log_link_warning_errno(link, r, "Failed to acquire random data to generate MAC address: %m");
-
+ random_bytes(p, len);
if (hw_addr_is_valid(link, &hw_addr))
break;
}