mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
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 <huangchenghai2@huawei.com>
Fixes: f1440a9046 ("crypto: api - Add support for duplicating algorithms before registration")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
4e721fe9cb
commit
1dfb35de08
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user