crypto: Demote BUG_ON() in crypto_unregister_alg() to a WARN_ON()
Subsystems (2)
PATCH 1/1 crypto: Demote BUG_ON() in crypto_unregister_alg() to a WARN_ON()
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() to WARN_ON() in crypto_unregister_alg(). Cc stable because this problem was observed on a 6.2 kernel, cf the link below.
--- crypto/algapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/algapi.c +1 -1
@@ -493,7 +493,7 @@ 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 ); +WARN_ON (refcount_read (&alg->cra_refcnt) !=1 );if (alg->cra_destroy) alg->cra_destroy (alg);
Signature · 1 line
2.39.2
Herbert Xu
maintainercrypto/algapi.c void crypto_unregister_alg(struct crypto_alg *alg) · line 496
Quoted 11 lines · Toke Høiland-Jørgensen
crypto/algapi.c +1
-1@@ -493,7 +493,7 @@ 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 ); +WARN_ON (refcount_read (&alg->cra_refcnt) !=1 );
I think we should return here instead of continuing to destroy the algorithm since we know that it's still in use.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Greg KH
maintainerQuoted 10 lines · Herbert Xu
Quoted 9 lines · Toke Høiland-Jørgensen
crypto/algapi.c +0
-0@@ -493,7 +493,7 @@ void crypto_unregister_alg(struct crypto_alg *alg)if (WARN (ret,"Algorithm %s is not registered" , alg->cra_driver_name))return ;
Quoted 5 lines
crypto/algapi.c void crypto_unregister_alg(struct crypto_alg *alg) · line 496
Quoted 2 lines
crypto/algapi.c +1
-1-BUG_ON (refcount_read (&alg->cra_refcnt) !=1 ); +WARN_ON (refcount_read (&alg->cra_refcnt) !=1 );I think we should return here instead of continuing to destroy the algorithm since we know that it's still in use.
Also, this still panics a box with panic-on-warn enabled, so if this can be handled, returning an error is good.
thanks,
greg k-h
Herbert Xu
maintainerQuoted 3 lines · Greg KH
Also, this still panics a box with panic-on-warn enabled, so if this can be handled, returning an error is good.
Well it can't really be handled because the driver is trying to unregister an in-use algorithm so it's going to die one way or another.
But returning here at least means that if this is happening through shutdown then the system at least gets a chance to reboot.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt