aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-06-21 07:11:43 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-22 03:49:18 -0400
commit7cecadb7cca83953e7857fe9f7273b705cb8ebe7 (patch)
treec799593db728356d1c2485e1d21799a2da1f5c89
parent21dbd96f2287a49219d35a0e916cf3f2bcaab9d0 (diff)
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>
-rw-r--r--crypto/rng.c27
-rw-r--r--include/crypto/internal/rng.h9
2 files changed, 32 insertions, 4 deletions
diff --git a/crypto/rng.c b/crypto/rng.c
index 13155058b193..b81cffb13bab 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -155,14 +155,33 @@ EXPORT_SYMBOL_GPL(crypto_get_default_rng);
155void crypto_put_default_rng(void) 155void crypto_put_default_rng(void)
156{ 156{
157 mutex_lock(&crypto_default_rng_lock); 157 mutex_lock(&crypto_default_rng_lock);
158 if (!--crypto_default_rng_refcnt) { 158 crypto_default_rng_refcnt--;
159 crypto_free_rng(crypto_default_rng);
160 crypto_default_rng = NULL;
161 }
162 mutex_unlock(&crypto_default_rng_lock); 159 mutex_unlock(&crypto_default_rng_lock);
163} 160}
164EXPORT_SYMBOL_GPL(crypto_put_default_rng); 161EXPORT_SYMBOL_GPL(crypto_put_default_rng);
165 162
163#if defined(CONFIG_CRYPTO_RNG) || defined(CONFIG_CRYPTO_RNG_MODULE)
164int crypto_del_default_rng(void)
165{
166 int err = -EBUSY;
167
168 mutex_lock(&crypto_default_rng_lock);
169 if (crypto_default_rng_refcnt)
170 goto out;
171
172 crypto_free_rng(crypto_default_rng);
173 crypto_default_rng = NULL;
174
175 err = 0;
176
177out:
178 mutex_unlock(&crypto_default_rng_lock);
179
180 return err;
181}
182EXPORT_SYMBOL_GPL(crypto_del_default_rng);
183#endif
184
166int crypto_register_rng(struct rng_alg *alg) 185int crypto_register_rng(struct rng_alg *alg)
167{ 186{
168 struct crypto_alg *base = &alg->base; 187 struct crypto_alg *base = &alg->base;
diff --git a/include/crypto/internal/rng.h b/include/crypto/internal/rng.h
index 263f1a5eebc7..a52ef3483dd7 100644
--- a/include/crypto/internal/rng.h
+++ b/include/crypto/internal/rng.h
@@ -22,6 +22,15 @@ void crypto_unregister_rng(struct rng_alg *alg);
22int crypto_register_rngs(struct rng_alg *algs, int count); 22int crypto_register_rngs(struct rng_alg *algs, int count);
23void crypto_unregister_rngs(struct rng_alg *algs, int count); 23void crypto_unregister_rngs(struct rng_alg *algs, int count);
24 24
25#if defined(CONFIG_CRYPTO_RNG) || defined(CONFIG_CRYPTO_RNG_MODULE)
26int crypto_del_default_rng(void);
27#else
28static inline int crypto_del_default_rng(void)
29{
30 return 0;
31}
32#endif
33
25static inline void *crypto_rng_ctx(struct crypto_rng *tfm) 34static inline void *crypto_rng_ctx(struct crypto_rng *tfm)
26{ 35{
27 return crypto_tfm_ctx(&tfm->base); 36 return crypto_tfm_ctx(&tfm->base);