[PATCH 3/4] crypto: akcipher - Retain alg refcount in crypto_grab_akcipher

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch changes crypto_grab_akcipher to retain the reference count
on the algorithm.  This is because the caller needs to access the
algorithm parameters and without the reference count the algorithm
can be freed at any time.

All callers have been modified to drop the reference count instead.

Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
---

 crypto/akcipher.c                  |    7 +------
 crypto/rsa-pkcs1pad.c              |    3 +++
 include/crypto/internal/akcipher.h |    5 +++++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/crypto/akcipher.c b/crypto/akcipher.c
index ce3471102120..7d5cf4939423 100644
--- a/crypto/akcipher.c
+++ b/crypto/akcipher.c
@@ -93,13 +93,8 @@ static const struct crypto_type crypto_akcipher_type = {
 int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name,
 			 u32 type, u32 mask)
 {
-	int err;
-
 	spawn->base.frontend = &crypto_akcipher_type;
-	err = crypto_grab_spawn(&spawn->base, name, type, mask);
-	if (!err)
-		crypto_mod_put(spawn->base.alg);
-	return err;
+	return crypto_grab_spawn(&spawn->base, name, type, mask);
 }
 EXPORT_SYMBOL_GPL(crypto_grab_akcipher);
 
diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c
index 0aa489711ec4..c445e93216e1 100644
--- a/crypto/rsa-pkcs1pad.c
+++ b/crypto/rsa-pkcs1pad.c
@@ -692,10 +692,13 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb)
 	if (err)
 		goto out_drop_alg;
 
+	akcipher_alg_put(rsa_alg);
+
 	return 0;
 
 out_drop_alg:
 	crypto_drop_akcipher(spawn);
+	akcipher_alg_put(rsa_alg);
 out_free_inst:
 	kfree(inst);
 	return err;
diff --git a/include/crypto/internal/akcipher.h b/include/crypto/internal/akcipher.h
index d6c8a42789ad..10c36ed22b78 100644
--- a/include/crypto/internal/akcipher.h
+++ b/include/crypto/internal/akcipher.h
@@ -105,6 +105,11 @@ static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
 	return container_of(spawn->base.alg, struct akcipher_alg, base);
 }
 
+static inline void akcipher_alg_put(struct akcipher_alg *alg)
+{
+	crypto_mod_put(&alg->base);
+}
+
 /**
  * crypto_register_akcipher() -- Register public key algorithm
  *



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux