summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-05-14 13:09:17 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2022-05-19 16:54:15 +0200
commit248561ad25a8ba4ecbc7df42f9a5a82fd5fbb4f6 (patch)
tree0bc8a927e8481e0b62600496e2a6376938e3e12d /lib
parent560181c27b582557d633ecb608110075433383af (diff)
random: remove get_random_bytes_arch() and add rng_has_arch_random()
The RNG incorporates RDRAND into its state at boot and every time it reseeds, so there's no reason for callers to use it directly. The hashing that the RNG does on it is preferable to using the bytes raw. The only current use case of get_random_bytes_arch() is vsprintf's siphash key for pointer hashing, which uses it to initialize the pointer secret earlier than usual if RDRAND is available. In order to replace this narrow use case, just expose whether RDRAND is mixed into the RNG, with a new function called rng_has_arch_random(). With that taken care of, there are no users of get_random_bytes_arch() left, so it can be removed. Later, if trust_cpu gets turned on by default (as most distros are doing), this one use of rng_has_arch_random() can probably go away as well. Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Acked-by: Petr Mladek <pmladek@suse.com> # for vsprintf.c Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 40d26a07a133..20e9887faaaa 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -776,12 +776,11 @@ static struct notifier_block random_ready = {
static int __init initialize_ptr_random(void)
{
- int key_size = sizeof(ptr_key);
int ret;
- /* Use hw RNG if available. */
- if (get_random_bytes_arch(&ptr_key, key_size) == key_size) {
- static_branch_disable(&not_filled_random_ptr_key);
+ /* Don't bother waiting for RNG to be ready if RDRAND is mixed in already. */
+ if (rng_has_arch_random()) {
+ enable_ptr_key_workfn(&enable_ptr_key_work);
return 0;
}