summaryrefslogtreecommitdiff
path: root/crypto/algapi.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2019-12-07 22:15:15 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-02-11 04:35:31 -0800
commitf0a235bd332c3568b2b1b7d32c08a5dfc02c3b64 (patch)
tree67754e75e47f6c9adb056987beff434dcb293dea /crypto/algapi.c
parenta9edfdb29f48bdea757bbd057cab816edf58b4d2 (diff)
downloadlinux-crypto-f0a235bd332c3568b2b1b7d32c08a5dfc02c3b64.tar.gz
linux-crypto-f0a235bd332c3568b2b1b7d32c08a5dfc02c3b64.zip
crypto: api - Fix race condition in crypto_spawn_alg
commit bc1d8cb6169a2deb7dbcad8ac6ed8ade1bc2bb05 upstream. The function crypto_spawn_alg is racy because it drops the lock before shooting the dying algorithm. The algorithm could disappear altogether before we shoot it. This patch fixes it by moving the shooting into the locked section. Fixes: 525ed3dcb430 ("[CRYPTO] api: Added spawns") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 5167a4f6..bb8329e4 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -697,22 +697,16 @@ EXPORT_SYMBOL_GPL(crypto_drop_spawn);
static struct crypto_alg *crypto_spawn_alg(struct crypto_spawn *spawn)
{
struct crypto_alg *alg;
- struct crypto_alg *alg2;
down_read(&crypto_alg_sem);
alg = spawn->alg;
- alg2 = alg;
- if (alg2)
- alg2 = crypto_mod_get(alg2);
- up_read(&crypto_alg_sem);
-
- if (!alg2) {
- if (alg)
- crypto_shoot_alg(alg);
- return ERR_PTR(-EAGAIN);
+ if (alg && !crypto_mod_get(alg)) {
+ alg->cra_flags |= CRYPTO_ALG_DYING;
+ alg = NULL;
}
+ up_read(&crypto_alg_sem);
- return alg;
+ return alg ?: ERR_PTR(-EAGAIN);
}
struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,