Skip to content

Commit e2bfdde

Browse files
herbertxkamalmostafa
authored andcommitted
crypto: api - Fix race condition in larval lookup
commit 77dbd7a upstream. 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. Reported-by: Kees Cook <[email protected]> Tested-by: Kees Cook <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]>
1 parent 342c71e commit e2bfdde

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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)