Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b170a137 authored by Herbert Xu's avatar Herbert Xu
Browse files

crypto: skcipher - Avoid infinite loop when cipher fails selftest



When an skcipher constructed through crypto_givcipher_default fails
its selftest, we'll loop forever trying to construct new skcipher
objects but failing because it already exists.

The crux of the issue is that once a givcipher fails the selftest,
we'll ignore it on the next run through crypto_skcipher_lookup and
attempt to construct a new givcipher.

We should instead return an error to the caller if we find a
givcipher that has failed the test.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 3f683d61
Loading
Loading
Loading
Loading
+19 −0
Original line number Original line Diff line number Diff line
@@ -282,6 +282,25 @@ static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type,
					  alg->cra_ablkcipher.ivsize))
					  alg->cra_ablkcipher.ivsize))
		return alg;
		return alg;


	crypto_mod_put(alg);
	alg = crypto_alg_mod_lookup(name, type | CRYPTO_ALG_TESTED,
				    mask & ~CRYPTO_ALG_TESTED);
	if (IS_ERR(alg))
		return alg;

	if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
	    CRYPTO_ALG_TYPE_GIVCIPHER) {
		if ((alg->cra_flags ^ type ^ ~mask) & CRYPTO_ALG_TESTED) {
			crypto_mod_put(alg);
			alg = ERR_PTR(-ENOENT);
		}
		return alg;
	}

	BUG_ON(!((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
		 CRYPTO_ALG_TYPE_BLKCIPHER ? alg->cra_blkcipher.ivsize :
					     alg->cra_ablkcipher.ivsize));

	return ERR_PTR(crypto_givcipher_default(alg, type, mask));
	return ERR_PTR(crypto_givcipher_default(alg, type, mask));
}
}


+1 −1

File changed.

Contains only whitespace changes.