Skip to content

Commit b346e49

Browse files
ebiggersherbertx
authored andcommitted
crypto: api - fix finding algorithm currently being tested
Commit eb02c38 ("crypto: api - Keep failed instances alive") is making allocating crypto transforms sometimes fail with ELIBBAD, when multiple processes try to access encrypted files with fscrypt for the first time since boot. The problem is that the "request larval" for the algorithm is being mistaken for an algorithm which failed its tests. Fix it by only returning ELIBBAD for "non-larval" algorithms. Also don't leak a reference to the algorithm. Fixes: eb02c38 ("crypto: api - Keep failed instances alive") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 60cc43f commit b346e49

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crypto/api.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,14 @@ static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
204204

205205
down_read(&crypto_alg_sem);
206206
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;
207+
if (!alg && test) {
208+
alg = __crypto_alg_lookup(name, type, mask);
209+
if (alg && !crypto_is_larval(alg)) {
210+
/* Test failed */
211+
crypto_mod_put(alg);
212+
alg = ERR_PTR(-ELIBBAD);
213+
}
214+
}
210215
up_read(&crypto_alg_sem);
211216

212217
return alg;

0 commit comments

Comments
 (0)