aboutsummaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorJason A. Donenfeld2022-03-01 20:22:39 +0100
committerJason A. Donenfeld2022-03-12 18:00:56 -0700
commitf3c2682bad7bc6033c837e9c66e5af881fe8d465 (patch)
treef0101c73dee541fd4cd6e599e26f5e5b1195190e /drivers/char
parent5acd35487dc911541672b3ffc322851769c32a56 (diff)
random: provide notifier for VM fork
Drivers such as WireGuard need to learn when VMs fork in order to clear sessions. This commit provides a simple notifier_block for that, with a register and unregister function. When no VM fork detection is compiled in, this turns into a no-op, similar to how the power notifier works. Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index aa7bc9a3a864..d9ca441c14bd 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1140,6 +1140,8 @@ void add_bootloader_randomness(const void *buf, size_t size)
EXPORT_SYMBOL_GPL(add_bootloader_randomness);
#if IS_ENABLED(CONFIG_VMGENID)
+static BLOCKING_NOTIFIER_HEAD(vmfork_chain);
+
/*
* Handle a new unique VM ID, which is unique, not secret, so we
* don't credit it, but we do immediately force a reseed after so
@@ -1152,10 +1154,23 @@ void add_vmfork_randomness(const void *unique_vm_id, size_t size)
crng_reseed(true);
pr_notice("crng reseeded due to virtual machine fork\n");
}
+ blocking_notifier_call_chain(&vmfork_chain, 0, NULL);
}
#if IS_MODULE(CONFIG_VMGENID)
EXPORT_SYMBOL_GPL(add_vmfork_randomness);
#endif
+
+int register_random_vmfork_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(&vmfork_chain, nb);
+}
+EXPORT_SYMBOL_GPL(register_random_vmfork_notifier);
+
+int unregister_random_vmfork_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(&vmfork_chain, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_random_vmfork_notifier);
#endif
struct fast_pool {