crypto: api - Fix DUP_FIRST crash on unregister

The flag CRYPTO_ALG_DUP_FIRST is buggy because upon unregistration
it tries to unregister the original algorithm rather than the
duplicate which was allocated during registration.

Fix this by locating the duplicated algorithm and unregistering
that instead of the original.

Also remove the duplicate crypto_destroy_alg call.

Reported-by: Chenghai Huang <[email protected]>
Fixes: f1440a9046 ("crypto: api - Add support for duplicating algorithms before registration")
Signed-off-by: Herbert Xu <[email protected]>
This commit is contained in:
Herbert Xu
2026-09-23 18:38:40 +10:00
parent 4e721fe9cb
commit 1dfb35de08
+22 -1
View File
@@ -424,7 +424,6 @@ static void crypto_free_alg(struct crypto_alg *alg)
unsigned int algsize = alg->cra_type->algsize;
u8 *p = (u8 *)alg - algsize;
crypto_destroy_alg(alg);
kfree(p);
}
@@ -494,9 +493,31 @@ void crypto_unregister_alg(struct crypto_alg *alg)
LIST_HEAD(list);
down_write(&crypto_alg_sem);
if (alg->cra_flags & CRYPTO_ALG_DUP_FIRST) {
struct crypto_alg *q, *r = NULL;
list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (crypto_is_larval(q))
continue;
if (strcmp(q->cra_driver_name, alg->cra_driver_name))
continue;
r = q;
break;
}
if (!r) {
up_write(&crypto_alg_sem);
ret = -ENOENT;
goto not_found;
}
alg = r;
}
ret = crypto_remove_alg(alg, &list);
up_write(&crypto_alg_sem);
not_found:
if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name))
return;