Skip to content

Commit dcc9ff8

Browse files
tohojosmb49
authored andcommitted
crypto: api - Demote BUG_ON() in crypto_unregister_alg() to a WARN_ON()
BugLink: https://bugs.launchpad.net/bugs/2025095 commit a543ada 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> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent 4e42dab commit dcc9ff8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crypto/algapi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ void crypto_unregister_alg(struct crypto_alg *alg)
456456
if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name))
457457
return;
458458

459-
BUG_ON(refcount_read(&alg->cra_refcnt) != 1);
459+
if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1))
460+
return;
461+
460462
if (alg->cra_destroy)
461463
alg->cra_destroy(alg);
462464

0 commit comments

Comments
 (0)