From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-efi@vger.kernel.org, linux-crypto@vger.kernel.org,
patches@lists.linux.dev, linux-kernel@vger.kernel.org,
ardb@kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>, Petr Mladek <pmladek@suse.com>
Subject: [PATCH v3 4/5] vsprintf: initialize siphash key using notifier
Date: Tue, 22 Nov 2022 03:04:03 +0100 [thread overview]
Message-ID: <20221122020404.3476063-5-Jason@zx2c4.com> (raw)
In-Reply-To: <20221122020404.3476063-1-Jason@zx2c4.com>
Rather than polling every second, use the new notifier to do this at
exactly the right moment.
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
lib/vsprintf.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 24f37bab8bc1..2d11541ee561 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -41,6 +41,7 @@
#include <linux/siphash.h>
#include <linux/compiler.h>
#include <linux/property.h>
+#include <linux/notifier.h>
#ifdef CONFIG_BLOCK
#include <linux/blkdev.h>
#endif
@@ -752,26 +753,21 @@ early_param("debug_boot_weak_hash", debug_boot_weak_hash_enable);
static bool filled_random_ptr_key __read_mostly;
static siphash_key_t ptr_key __read_mostly;
-static void fill_ptr_key_workfn(struct work_struct *work);
-static DECLARE_DELAYED_WORK(fill_ptr_key_work, fill_ptr_key_workfn);
-static void fill_ptr_key_workfn(struct work_struct *work)
+static int fill_ptr_key(struct notifier_block *nb, unsigned long action, void *data)
{
- if (!rng_is_initialized()) {
- queue_delayed_work(system_unbound_wq, &fill_ptr_key_work, HZ * 2);
- return;
- }
-
get_random_bytes(&ptr_key, sizeof(ptr_key));
/* Pairs with smp_rmb() before reading ptr_key. */
smp_wmb();
WRITE_ONCE(filled_random_ptr_key, true);
+ return NOTIFY_DONE;
}
static int __init vsprintf_init_hashval(void)
{
- fill_ptr_key_workfn(NULL);
+ static struct notifier_block fill_ptr_key_nb = { .notifier_call = fill_ptr_key };
+ execute_with_initialized_rng(&fill_ptr_key_nb);
return 0;
}
subsys_initcall(vsprintf_init_hashval)
--
2.38.1
next prev parent reply other threads:[~2022-11-22 2:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 2:03 [PATCH v3 0/5] Use EFI variables for random seed Jason A. Donenfeld
2022-11-22 2:04 ` [PATCH v3 1/5] efi: vars: prohibit reading random seed variables Jason A. Donenfeld
2022-11-27 21:00 ` Matthew Garrett
2022-11-28 1:10 ` Jason A. Donenfeld
2022-11-22 2:04 ` [PATCH v3 2/5] efi: stub: use random seed from EFI variable Jason A. Donenfeld
2022-11-27 21:12 ` Matthew Garrett
2022-11-28 1:12 ` Jason A. Donenfeld
2022-11-28 1:35 ` Matthew Garrett
2022-11-22 2:04 ` [PATCH v3 3/5] random: add back async readiness notifier Jason A. Donenfeld
2022-11-22 2:04 ` Jason A. Donenfeld [this message]
2022-11-22 2:04 ` [PATCH v3 5/5] efi: random: refresh non-volatile random seed when RNG is initialized Jason A. Donenfeld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221122020404.3476063-5-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=pmladek@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox