Skip to content

Commit b8e1599

Browse files
committed
crypto: api - Fix algorithm test race that broke aead initialisation
When we complete a test we'll notify everyone waiting on it, drop the mutex, and then remove the test larval (after reacquiring the mutex). If one of the notified parties tries to register another algorithm with the same driver name prior to the removal of the test larval, they will fail with EEXIST as only one algorithm of a given name can be tested at any time. This broke the initialisation of aead and givcipher algorithms as they will register two algorithms with the same driver name, in sequence. This patch fixes the problem by marking the larval as dead before we drop the mutex, and also ignoring all dead or dying algorithms on the registration path. Tested-by: Andreas Steffen <andreas.steffen@strongswan.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 516280e commit b8e1599

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎crypto/algapi.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
149149
if (q == alg)
150150
goto err;
151151

152+
if (crypto_is_moribund(q))
153+
continue;
154+
152155
if (crypto_is_larval(q)) {
153156
if (!strcmp(alg->cra_driver_name, q->cra_driver_name))
154157
goto err;
@@ -197,7 +200,7 @@ void crypto_alg_tested(const char *name, int err)
197200

198201
down_write(&crypto_alg_sem);
199202
list_for_each_entry(q, &crypto_alg_list, cra_list) {
200-
if (!crypto_is_larval(q))
203+
if (crypto_is_moribund(q) || !crypto_is_larval(q))
201204
continue;
202205

203206
test = (struct crypto_larval *)q;
@@ -210,6 +213,7 @@ void crypto_alg_tested(const char *name, int err)
210213
goto unlock;
211214

212215
found:
216+
q->cra_flags |= CRYPTO_ALG_DEAD;
213217
alg = test->adult;
214218
if (err || list_empty(&alg->cra_list))
215219
goto complete;

0 commit comments

Comments
 (0)