summaryrefslogtreecommitdiff
path: root/src/journal/journalctl.c
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/journal/journalctl.c
parentfada4bdcaa57137c7245d3031deb08f3bcf7a8cc (diff)
downloadsystemd-87cb1ab6765d9ad9482b882b26e45a683162a078.tar.gz
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/journal/journalctl.c')
-rw-r--r--src/journal/journalctl.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index cff34fd585..046b48184a 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1909,7 +1909,7 @@ static int setup_keys(void) {
state = alloca_safe(state_size);
log_info("Generating seed...");
- r = genuine_random_bytes(seed, seed_size, RANDOM_BLOCK);
+ r = crypto_random_bytes(seed, seed_size);
if (r < 0)
return log_error_errno(r, "Failed to acquire random seed: %m");