All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Subject: [PATCH v2 6/6] crypto: algapi - enforce that all instances have a ->free() method
Date: Thu,  2 Jan 2020 20:04:40 -0800	[thread overview]
Message-ID: <20200103040440.12375-7-ebiggers@kernel.org> (raw)
In-Reply-To: <20200103040440.12375-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

All instances need to have a ->free() method, but people could forget to
set it and then not notice if the instance is never unregistered.  To
help detect this bug earlier, don't allow an instance without a ->free()
method to be registered, and complain loudly if someone tries to do it.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/aead.c     | 3 +++
 crypto/ahash.c    | 3 +++
 crypto/akcipher.c | 2 ++
 crypto/shash.c    | 3 +++
 crypto/skcipher.c | 3 +++
 5 files changed, 14 insertions(+)

diff --git a/crypto/aead.c b/crypto/aead.c
index 7707d3223101..16991095270d 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -288,6 +288,9 @@ int aead_register_instance(struct crypto_template *tmpl,
 {
 	int err;
 
+	if (WARN_ON(!inst->free))
+		return -EINVAL;
+
 	err = aead_prepare_alg(&inst->alg);
 	if (err)
 		return err;
diff --git a/crypto/ahash.c b/crypto/ahash.c
index cd5d9847d513..68a0f0cb75c4 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -656,6 +656,9 @@ int ahash_register_instance(struct crypto_template *tmpl,
 {
 	int err;
 
+	if (WARN_ON(!inst->free))
+		return -EINVAL;
+
 	err = ahash_prepare_alg(&inst->alg);
 	if (err)
 		return err;
diff --git a/crypto/akcipher.c b/crypto/akcipher.c
index eeed6c151d2f..f866085c8a4a 100644
--- a/crypto/akcipher.c
+++ b/crypto/akcipher.c
@@ -147,6 +147,8 @@ EXPORT_SYMBOL_GPL(crypto_unregister_akcipher);
 int akcipher_register_instance(struct crypto_template *tmpl,
 			       struct akcipher_instance *inst)
 {
+	if (WARN_ON(!inst->free))
+		return -EINVAL;
 	akcipher_prepare_alg(&inst->alg);
 	return crypto_register_instance(tmpl, akcipher_crypto_instance(inst));
 }
diff --git a/crypto/shash.c b/crypto/shash.c
index 70faf28b2d14..c075b26c2a1d 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -577,6 +577,9 @@ int shash_register_instance(struct crypto_template *tmpl,
 {
 	int err;
 
+	if (WARN_ON(!inst->free))
+		return -EINVAL;
+
 	err = shash_prepare_alg(&inst->alg);
 	if (err)
 		return err;
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 8c37243307aa..ba41f81fac0b 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -876,6 +876,9 @@ int skcipher_register_instance(struct crypto_template *tmpl,
 {
 	int err;
 
+	if (WARN_ON(!inst->free))
+		return -EINVAL;
+
 	err = skcipher_prepare_alg(&inst->alg);
 	if (err)
 		return err;
-- 
2.24.1


  parent reply	other threads:[~2020-01-03  4:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-03  4:04 [PATCH v2 0/6] crypto: remove old way of allocating and freeing instances Eric Biggers
2020-01-03  4:04 ` [PATCH v2 1/6] crypto: hash - add support for new way of " Eric Biggers
2020-01-03  4:04 ` [PATCH v2 2/6] crypto: geniv - convert to " Eric Biggers
2020-01-03  4:04 ` [PATCH v2 3/6] crypto: cryptd " Eric Biggers
2020-01-03  4:04 ` [PATCH v2 4/6] crypto: shash - convert shash_free_instance() to new style Eric Biggers
2020-01-03  4:04 ` [PATCH v2 5/6] crypto: algapi - remove crypto_template::{alloc,free}() Eric Biggers
2020-01-03  4:04 ` Eric Biggers [this message]
2020-01-09  5:15 ` [PATCH v2 0/6] crypto: remove old way of allocating and freeing instances 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=20200103040440.12375-7-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.