Skip to content

Commit eb02c38

Browse files
committed
crypto: api - Keep failed instances alive
This patch reverts commit 9c521a2 ("crypto: api - remove instance when test failed") and fixes the underlying problem in a different way. To recap, prior to the reverted commit, an instance that fails a self-test is kept around. However, it would satisfy any new lookups against its name and therefore the system may accumlulate an unbounded number of failed instances for the same algorithm name. The reverted commit fixed it by unregistering the instance. Hoever, this still does not prevent the creation of the same failed instance over and over again each time the name is looked up. This patch fixes it by keeping the failed instance around, just as we would if it were a normal algorithm. However, the lookup code has been udpated so that we do not attempt to create another instance as long as this failed one is still registered. Of course, you could still force a new creation by deleting the instance from user-space. A new error (ELIBBAD) has been commandeered for this purpose and will be returned when all registered algorithm of a given name have failed the self-test. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 3ca1e99 commit eb02c38

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

crypto/algapi.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,6 @@ int crypto_register_instance(struct crypto_template *tmpl,
543543
inst->alg.cra_module = tmpl->module;
544544
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
545545

546-
if (unlikely(!crypto_mod_get(&inst->alg)))
547-
return -EAGAIN;
548-
549546
down_write(&crypto_alg_sem);
550547

551548
larval = __crypto_register_alg(&inst->alg);
@@ -563,14 +560,9 @@ int crypto_register_instance(struct crypto_template *tmpl,
563560
goto err;
564561

565562
crypto_wait_for_test(larval);
566-
567-
/* Remove instance if test failed */
568-
if (!(inst->alg.cra_flags & CRYPTO_ALG_TESTED))
569-
crypto_unregister_instance(inst);
570563
err = 0;
571564

572565
err:
573-
crypto_mod_put(&inst->alg);
574566
return err;
575567
}
576568
EXPORT_SYMBOL_GPL(crypto_register_instance);

crypto/api.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,16 @@ static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
197197
u32 mask)
198198
{
199199
struct crypto_alg *alg;
200+
u32 test = 0;
201+
202+
if (!((type | mask) & CRYPTO_ALG_TESTED))
203+
test |= CRYPTO_ALG_TESTED;
200204

201205
down_read(&crypto_alg_sem);
202-
alg = __crypto_alg_lookup(name, type, mask);
206+
alg = __crypto_alg_lookup(name, type | test, mask | test);
207+
if (!alg && test)
208+
alg = __crypto_alg_lookup(name, type, mask) ?
209+
ERR_PTR(-ELIBBAD) : NULL;
203210
up_read(&crypto_alg_sem);
204211

205212
return alg;
@@ -227,10 +234,12 @@ static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type,
227234
alg = crypto_alg_lookup(name, type, mask);
228235
}
229236

230-
if (alg)
231-
return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
237+
if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg))
238+
alg = crypto_larval_wait(alg);
239+
else if (!alg)
240+
alg = crypto_larval_add(name, type, mask);
232241

233-
return crypto_larval_add(name, type, mask);
242+
return alg;
234243
}
235244

236245
int crypto_probing_notify(unsigned long val, void *v)
@@ -253,11 +262,6 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
253262
struct crypto_alg *larval;
254263
int ok;
255264

256-
if (!((type | mask) & CRYPTO_ALG_TESTED)) {
257-
type |= CRYPTO_ALG_TESTED;
258-
mask |= CRYPTO_ALG_TESTED;
259-
}
260-
261265
/*
262266
* If the internal flag is set for a cipher, require a caller to
263267
* to invoke the cipher with the internal flag to use that cipher.

0 commit comments

Comments
 (0)