From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: [PATCH 3/4] crypto: akcipher - Retain alg refcount in crypto_grab_akcipher
Date: Fri, 06 Dec 2019 14:38:38 +0800 [thread overview]
Message-ID: <E1id7GA-00051Q-9U@gondobar> (raw)
In-Reply-To: 20191206063812.ueudgjfwzri5ekpr@gondor.apana.org.au
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@gondor.apana.org.au>
---
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
*
next prev parent reply other threads:[~2019-12-06 6:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-06 6:38 [PATCH 0/4] crypto: api - Retain grabbed refcount until registration Herbert Xu
2019-12-06 6:38 ` [PATCH 1/4] crypto: api - Retain alg refcount in crypto_grab_spawn Herbert Xu
2019-12-06 22:31 ` Eric Biggers
2019-12-06 6:38 ` [PATCH 2/4] crypto: aead - Retain alg refcount in crypto_grab_aead Herbert Xu
2019-12-06 22:41 ` Eric Biggers
2019-12-07 3:30 ` Herbert Xu
2019-12-07 4:52 ` Eric Biggers
2019-12-07 14:55 ` Herbert Xu
2019-12-14 6:44 ` [v2 PATCH] crypto: api - Retain alg refcount in crypto_grab_spawn Herbert Xu
2019-12-15 4:11 ` [v3 " Herbert Xu
2019-12-16 4:46 ` Eric Biggers
2019-12-18 7:53 ` [v4 " Herbert Xu
2019-12-06 6:38 ` Herbert Xu [this message]
2019-12-06 6:38 ` [PATCH 4/4] crypto: skcipher - Retain alg refcount in crypto_grab_skcipher Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1id7GA-00051Q-9U@gondobar \
--to=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox