Blob Blame History Raw
From e67e078e380361327b652b1bd7a3a257ff34ba43 Mon Sep 17 00:00:00 2001
From: Nicolai Stange <nstange@suse.de>
Date: Tue, 30 Nov 2021 20:19:58 +0100
Subject: [PATCH] crypto: dh - call dh_init() after drbg_init() and
 jent_mod_init()
References: jsc#SLE-21132,bsc#1191256
Patch-mainline: Never, upstream solves it in a more generic way

The upcoming DH privkey generation test vectors need access to the
crypto_default_rng instance, which gets registered via subsys_initcall().
So, if built-in DH gets registered via a subsys_initcall() as well, there
is a potential dependency ordering issue. Nothing depends upon DH being
available early, so call its dh_init() later during boot from
module_init().

jent_mod_init() currently gets invoked as a module_init(), which, as
the DRBGs depend on it, might be to late when the latter get instantiated
via the DH tests too being run at module_init(). Run jent_mod_init()
from a subsys_initcall() and drbg_init() from a subsys_initcall_sync()
in order to properly reflect the dependencies.

Note that this issue has been fixed differently upstream in a more generic
fashion, c.f. commit adad556efcdd ("crypto: api - Fix built-in testing
dependency failures").

Signed-off-by: Nicolai Stange <nstange@suse.de>
---
 crypto/dh.c                  |    2 +-
 crypto/drbg.c                |    2 +-
 crypto/jitterentropy-kcapi.c |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

--- a/crypto/dh.c
+++ b/crypto/dh.c
@@ -274,7 +274,7 @@ static void dh_exit(void)
 	crypto_unregister_kpp(&dh);
 }
 
-subsys_initcall(dh_init);
+module_init(dh_init);
 module_exit(dh_exit);
 MODULE_ALIAS_CRYPTO("dh");
 MODULE_LICENSE("GPL");
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -2147,7 +2147,7 @@ static void __exit drbg_exit(void)
 	crypto_unregister_rngs(drbg_algs, (ARRAY_SIZE(drbg_cores) * 2));
 }
 
-subsys_initcall(drbg_init);
+subsys_initcall_sync(drbg_init);
 module_exit(drbg_exit);
 #ifndef CRYPTO_DRBG_HASH_STRING
 #define CRYPTO_DRBG_HASH_STRING ""
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -208,7 +208,7 @@ static void __exit jent_mod_exit(void)
 	crypto_unregister_rng(&jent_alg);
 }
 
-module_init(jent_mod_init);
+subsys_initcall(jent_mod_init);
 module_exit(jent_mod_exit);
 
 MODULE_LICENSE("Dual BSD/GPL");