Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+4 -4
+4 -4
crypto/algapi.c
··· 481 481 if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) 482 482 return; 483 483 484 - if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1)) 485 - return; 486 - 487 - if (alg->cra_type && alg->cra_type->destroy) 484 + if (alg->cra_destroy) 485 + crypto_alg_put(alg); 486 + else if (!WARN_ON(refcount_read(&alg->cra_refcnt) != 1) && 487 + alg->cra_type && alg->cra_type->destroy) 488 488 alg->cra_type->destroy(alg); 489 489 490 490 crypto_remove_final(&list);