diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2025-04-09 11:29:03 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2025-04-16 15:16:22 +0800 |
commit | d701722aa343e59dd7c18fc62894edf4497251e2 (patch) | |
tree | a8bd81815656c5c01515c85ca35d0ebb712d1c04 /crypto/algapi.c | |
parent | c80d6598ffef3154698fb991c15211762cbf550e (diff) |
crypto: api - Allow delayed algorithm destruction
The current algorithm unregistration mechanism originated from
software crypto. The code relies on module reference counts to
stop in-use algorithms from being unregistered. Therefore if
the unregistration function is reached, it is assumed that the
module reference count has hit zero and thus the algorithm reference
count should be exactly 1.
This is completely broken for hardware devices, which can be
unplugged at random.
Fix this by allowing algorithms to be destroyed later if a destroy
callback is provided.
Reported-by: Sean Anderson <sean.anderson@linux.dev>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r-- | crypto/algapi.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index 5b8a4c787387..f368c0dc0d6d 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -481,10 +481,10 @@ void crypto_unregister_alg(struct crypto_alg *alg) if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) return; - if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1)) - return; - - if (alg->cra_type && alg->cra_type->destroy) + if (alg->cra_destroy) + crypto_alg_put(alg); + else if (!WARN_ON(refcount_read(&alg->cra_refcnt) != 1) && + alg->cra_type && alg->cra_type->destroy) alg->cra_type->destroy(alg); crypto_remove_final(&list); |