From: Wentao Liang <vulab@iscas.ac.cn>
To: ayush.sawal@chelsio.com, herbert@gondor.apana.org.au
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] crypto: chcr - Free fallback transforms when device assignment fails
Date: Tue, 3 Nov 2026 06:38:50 +0000 [thread overview]
Message-ID: <20261103063850.1033008-1-vulab@iscas.ac.cn> (raw)
The skcipher, RFC3686 and AEAD initialization callbacks allocate their
fallback transforms before calling chcr_device_init(). If no active
device can be assigned, chcr_device_init() returns -ENXIO and the
fallback is leaked. The crypto core does not invoke the algorithm's
exit callback after its initialization callback fails.
Free the fallback transform before returning the device assignment
error in each of these initialization callbacks.
Fixes: b8fd1f4170e7 ("crypto: chcr - Add ctr mode and process large sg entries for cipher")
Fixes: 0e93708dabc0 ("crypto: chcr - Add fallback for AEAD algos")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/crypto/chelsio/chcr_algo.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c
index e2f2b2a6200e..fd4720fa50a9 100644
--- a/drivers/crypto/chelsio/chcr_algo.c
+++ b/drivers/crypto/chelsio/chcr_algo.c
@@ -1439,6 +1439,7 @@ static int chcr_init_tfm(struct crypto_skcipher *tfm)
struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct chcr_context *ctx = crypto_skcipher_ctx(tfm);
struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
+ int ret;
ablkctx->sw_cipher = crypto_alloc_skcipher(alg->base.cra_name, 0,
CRYPTO_ALG_NEED_FALLBACK);
@@ -1450,7 +1451,11 @@ static int chcr_init_tfm(struct crypto_skcipher *tfm)
crypto_skcipher_set_reqsize(tfm, sizeof(struct chcr_skcipher_req_ctx) +
crypto_skcipher_reqsize(ablkctx->sw_cipher));
- return chcr_device_init(ctx);
+ ret = chcr_device_init(ctx);
+ if (ret)
+ crypto_free_skcipher(ablkctx->sw_cipher);
+
+ return ret;
}
static int chcr_rfc3686_init(struct crypto_skcipher *tfm)
@@ -1458,6 +1463,7 @@ static int chcr_rfc3686_init(struct crypto_skcipher *tfm)
struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct chcr_context *ctx = crypto_skcipher_ctx(tfm);
struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
+ int ret;
/*RFC3686 initialises IV counter value to 1, rfc3686(ctr(aes))
* cannot be used as fallback in chcr_handle_cipher_response
@@ -1470,7 +1476,11 @@ static int chcr_rfc3686_init(struct crypto_skcipher *tfm)
}
crypto_skcipher_set_reqsize(tfm, sizeof(struct chcr_skcipher_req_ctx) +
crypto_skcipher_reqsize(ablkctx->sw_cipher));
- return chcr_device_init(ctx);
+ ret = chcr_device_init(ctx);
+ if (ret)
+ crypto_free_skcipher(ablkctx->sw_cipher);
+
+ return ret;
}
@@ -3164,6 +3174,7 @@ static int chcr_aead_cra_init(struct crypto_aead *tfm)
{
struct chcr_aead_ctx *aeadctx = AEAD_CTX(a_ctx(tfm));
struct aead_alg *alg = crypto_aead_alg(tfm);
+ int ret;
aeadctx->sw_cipher = crypto_alloc_aead(alg->base.cra_name, 0,
CRYPTO_ALG_NEED_FALLBACK |
@@ -3174,7 +3185,11 @@ static int chcr_aead_cra_init(struct crypto_aead *tfm)
tfm, max(sizeof(struct chcr_aead_reqctx),
sizeof(struct aead_request) +
crypto_aead_reqsize(aeadctx->sw_cipher)));
- return chcr_device_init(a_ctx(tfm));
+ ret = chcr_device_init(a_ctx(tfm));
+ if (ret)
+ crypto_free_aead(aeadctx->sw_cipher);
+
+ return ret;
}
static void chcr_aead_cra_exit(struct crypto_aead *tfm)
--
2.34.1
next reply other threads:[~2026-11-03 6:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 6:38 Wentao Liang [this message]
2026-11-03 7:27 ` Krzysztof Kozlowski
2026-11-13 13:05 ` 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=20261103063850.1033008-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=ayush.sawal@chelsio.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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
all inboxes | Powered by JetHome®