diff options
| author | Toke Høiland-Jørgensen <toke@redhat.com> | 2023-03-13 10:17:24 +0100 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-05-11 23:00:17 +0900 |
| commit | 63b7fbaa1278434fcf4b6c7f1e08076f50f9c6ba (patch) | |
| tree | 7fdb2315959a1a52315623fd8c4b5bb1756cfcdc /crypto | |
| parent | c63741e872fcfb10e153517750f7908f0c00f60d (diff) | |
| download | linux-63b7fbaa1278434fcf4b6c7f1e08076f50f9c6ba.tar.gz linux-63b7fbaa1278434fcf4b6c7f1e08076f50f9c6ba.tar.bz2 linux-63b7fbaa1278434fcf4b6c7f1e08076f50f9c6ba.zip | |
crypto: api - Demote BUG_ON() in crypto_unregister_alg() to a WARN_ON()
commit a543ada7db729514ddd3ba4efa45f4c7b802ad85 upstream.
The crypto_unregister_alg() function expects callers to ensure that any
algorithm that is unregistered has a refcnt of exactly 1, and issues a
BUG_ON() if this is not the case. However, there are in fact drivers that
will call crypto_unregister_alg() without ensuring that the refcnt has been
lowered first, most notably on system shutdown. This causes the BUG_ON() to
trigger, which prevents a clean shutdown and hangs the system.
To avoid such hangs on shutdown, demote the BUG_ON() in
crypto_unregister_alg() to a WARN_ON() with early return. Cc stable because
this problem was observed on a 6.2 kernel, cf the link below.
Link: https://lore.kernel.org/r/87r0tyq8ph.fsf@toke.dk
Cc: stable@vger.kernel.org
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/algapi.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index f3d95af3e428..c1af76ec65f5 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -456,7 +456,9 @@ void crypto_unregister_alg(struct crypto_alg *alg) if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) return; - BUG_ON(refcount_read(&alg->cra_refcnt) != 1); + if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1)) + return; + if (alg->cra_destroy) alg->cra_destroy(alg); |
