[PATCH] crypto/algapi: fix refcount leak in crypto_register_alg()

From: Wentao Liang

Date: Tue Jun 02 2026 - 22:42:11 EST


In crypto_register_alg(), if the algorithm registration fails after
a successful crypto_alg_get() on the template algorithm, the acquired
reference is never released. This can occur when the new algorithm is
not allowed to be registered due to a constraint check failure.

Fix the leak by adding a corresponding crypto_alg_put() call in the
error path before returning.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: f1440a90465b ("crypto: api - Add support for duplicating algorithms before registration")
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
crypto/algapi.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/crypto/algapi.c b/crypto/algapi.c
index 37de377719ae..b0e4b13131c3 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -447,6 +447,7 @@ int crypto_register_alg(struct crypto_alg *alg)

p = kmemdup(p, algsize + sizeof(*alg), GFP_KERNEL);
if (!p)
+ crypto_alg_put(alg);
return -ENOMEM;

alg = (void *)(p + algsize);
--
2.34.1