summaryrefslogtreecommitdiff
path: root/crypto/rng.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-06-21 19:11:43 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-22 15:49:18 +0800
commit68932e3c35878466fb98ef8007457a2b839f1874 (patch)
tree72e3c6f1278eb0347a4210ada7c4e31a64d8bcf2 /crypto/rng.c
parentf13a259a9ed4d39715c7e9d6231b8ed1ce2886c4 (diff)
downloadlinux-crypto-68932e3c35878466fb98ef8007457a2b839f1874.tar.gz
linux-crypto-68932e3c35878466fb98ef8007457a2b839f1874.zip
crypto: rng - Do not free default RNG when it becomes unused
Currently we free the default RNG when its use count hits zero. This was OK when the IV generators would latch onto the RNG at instance creation time and keep it until the instance is torn down. Now that IV generators only keep the RNG reference during init time this scheme causes the default RNG to come and go at a high frequencey. This is highly undesirable as we want to keep a single RNG in use unless the admin wants it to be removed. This patch changes the scheme so that the system RNG once allocated is never removed unless a specifically requested. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/rng.c')
-rw-r--r--crypto/rng.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/crypto/rng.c b/crypto/rng.c
index 13155058..b81cffb1 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -155,14 +155,33 @@ EXPORT_SYMBOL_GPL(crypto_get_default_rng);
void crypto_put_default_rng(void)
{
mutex_lock(&crypto_default_rng_lock);
- if (!--crypto_default_rng_refcnt) {
- crypto_free_rng(crypto_default_rng);
- crypto_default_rng = NULL;
- }
+ crypto_default_rng_refcnt--;
mutex_unlock(&crypto_default_rng_lock);
}
EXPORT_SYMBOL_GPL(crypto_put_default_rng);
+#if defined(CONFIG_CRYPTO_RNG) || defined(CONFIG_CRYPTO_RNG_MODULE)
+int crypto_del_default_rng(void)
+{
+ int err = -EBUSY;
+
+ mutex_lock(&crypto_default_rng_lock);
+ if (crypto_default_rng_refcnt)
+ goto out;
+
+ crypto_free_rng(crypto_default_rng);
+ crypto_default_rng = NULL;
+
+ err = 0;
+
+out:
+ mutex_unlock(&crypto_default_rng_lock);
+
+ return err;
+}
+EXPORT_SYMBOL_GPL(crypto_del_default_rng);
+#endif
+
int crypto_register_rng(struct rng_alg *alg)
{
struct crypto_alg *base = &alg->base;