crypto: algboss - don't wait during notifier callback
Subsystems (2)
PATCH 1/1 crypto: algboss - don't wait during notifier callback
From: Eric Biggers <[email protected]>
When a crypto template needs to be instantiated, CRYPTO_MSG_ALG_REQUEST is sent to crypto_chain. cryptomgr_schedule_probe() handles this by starting a thread to instantiate the template, then waiting for this thread to complete via crypto_larval::completion.
This can deadlock because instantiating the template may require loading modules, and this (apparently depending on userspace) may need to wait for the crc-t10dif module (lib/crc-t10dif.c) to be loaded. But crc-t10dif's module_init function uses crypto_register_notifier() and therefore takes crypto_chain.rwsem for write. That can't proceed until the notifier callback has finished, as it holds this semaphore for read.
Fix this by removing the wait on crypto_larval::completion from within cryptomgr_schedule_probe(). It's actually unnecessary because crypto_alg_mod_lookup() calls crypto_larval_wait() itself after sending CRYPTO_MSG_ALG_REQUEST.
This only actually became a problem in v4.20 due to commit b76377543b73 ("crc-t10dif: Pick better transform if one becomes available"), but the unnecessary wait was much older.
--- crypto/algboss.c | 2 -- 1 file changed, 2 deletions(-)
crypto/algboss.c +0 -2
@@ -178,8 +178,6 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)if (IS_ERR (thread)) goto err_put_larval; -wait_for_completion_interruptible (&larval->completion); -return NOTIFY_STOP ; err_put_larval:
Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Quoted 19 lines · Eric Biggers
From: Eric Biggers <[email protected]>
When a crypto template needs to be instantiated,
CRYPTO_MSG_ALG_REQUESTis sent tocrypto_chain.cryptomgr_schedule_probe()handles this by starting a thread to instantiate the template, then waiting for this thread to complete viacrypto_larval::completion.This can deadlock because instantiating the template may require loading modules, and this (apparently depending on userspace) may need to wait for the crc-t10dif module (
lib/crc-t10dif.c) to be loaded. But crc-t10dif'smodule_initfunction usescrypto_register_notifier()and therefore takes crypto_chain.rwsem for write. That can't proceed until the notifier callback has finished, as it holds this semaphore for read.Fix this by removing the wait on
crypto_larval::completionfrom withincryptomgr_schedule_probe(). It's actually unnecessary becausecrypto_alg_mod_lookup()callscrypto_larval_wait()itself after sendingCRYPTO_MSG_ALG_REQUEST.
Quoted 6 lines
This only actually became a problem in v4.20 due to commit
b76377543b73("crc-t10dif: Pick better transform if one becomes available"), but the unnecessary wait was much older.Reported-by Mike Gerow <[email protected]>
I forgot about the person who originally filed the bugzilla bug. Kai, if you're okay with it, let's also add:
Quoted 24 lines
Fixes 398710379f51 ("crypto: algapi - Move larval completion into algboss")Cc <[email protected]> # v3.6+Cc Martin K. Petersen <[email protected]>Signed-off-by Eric Biggers <[email protected]>--- crypto/algboss.c | 2 -- 1 file changed, 2 deletions(-)crypto/algboss.c +0
-2@@ -178,8 +178,6 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)if (IS_ERR (thread)) goto err_put_larval; -wait_for_completion_interruptible (&larval->completion); -return NOTIFY_STOP ; err_put_larval:Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
Herbert Xu
maintainerQuoted 29 lines · Eric Biggers
From: Eric Biggers <[email protected]>
When a crypto template needs to be instantiated,
CRYPTO_MSG_ALG_REQUESTis sent tocrypto_chain.cryptomgr_schedule_probe()handles this by starting a thread to instantiate the template, then waiting for this thread to complete viacrypto_larval::completion.This can deadlock because instantiating the template may require loading modules, and this (apparently depending on userspace) may need to wait for the crc-t10dif module (
lib/crc-t10dif.c) to be loaded. But crc-t10dif'smodule_initfunction usescrypto_register_notifier()and therefore takes crypto_chain.rwsem for write. That can't proceed until the notifier callback has finished, as it holds this semaphore for read.Fix this by removing the wait on
crypto_larval::completionfrom withincryptomgr_schedule_probe(). It's actually unnecessary becausecrypto_alg_mod_lookup()callscrypto_larval_wait()itself after sendingCRYPTO_MSG_ALG_REQUEST.This only actually became a problem in v4.20 due to commit
b76377543b73("crc-t10dif: Pick better transform if one becomes available"), but the unnecessary wait was much older.Reported-by Mike Gerow <[email protected]>Fixes 398710379f51 ("crypto: algapi - Move larval completion into algboss")Cc <[email protected]> # v3.6+Cc Martin K. Petersen <[email protected]>Signed-off-by Eric Biggers <[email protected]>
Quoted 3 lines
--- crypto/algboss.c | 2 -- 1 file changed, 2 deletions(-)
Patch applied. 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