Skip to content

Commit 77dbd7a

Browse files
committed
crypto: api - Fix race condition in larval lookup
crypto_larval_lookup should only return a larval if it created one. Any larval created by another entity must be processed through crypto_larval_wait before being returned. Otherwise this will lead to a larval being killed twice, which will most likely lead to a crash. Cc: stable@vger.kernel.org Reported-by: Kees Cook <keescook@chromium.org> Tested-by: Kees Cook <keescook@chromium.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 6be48f2 commit 77dbd7a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

crypto/api.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
3434
BLOCKING_NOTIFIER_HEAD(crypto_chain);
3535
EXPORT_SYMBOL_GPL(crypto_chain);
3636

37+
static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
38+
3739
struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
3840
{
3941
return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
@@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
144146
}
145147
up_write(&crypto_alg_sem);
146148

147-
if (alg != &larval->alg)
149+
if (alg != &larval->alg) {
148150
kfree(larval);
151+
if (crypto_is_larval(alg))
152+
alg = crypto_larval_wait(alg);
153+
}
149154

150155
return alg;
151156
}

0 commit comments

Comments
 (0)