Skip to content

Commit 0a3cf32

Browse files
committed
crypto: api - Redo lookup on EEXIST
When two crypto algorithm lookups occur at the same time with different names for the same algorithm, e.g., ctr(aes-generic) and ctr(aes), they will both be instantiated. However, only one of them can be registered. The second instantiation will fail with EEXIST. Avoid failing the second lookup by making it retry, but only once because there are tricky names such as gcm_base(ctr(aes),ghash) that will always fail, despite triggering instantiation and EEXIST. Reported-by: Ingo Franzki <ifranzki@linux.ibm.com> Fixes: 2825982 ("[CRYPTO] api: Added event notification") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 35de409 commit 0a3cf32

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crypto/api.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,19 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg,
219219
if (crypto_is_test_larval(larval))
220220
crypto_larval_kill(larval);
221221
alg = ERR_PTR(-ETIMEDOUT);
222-
} else if (!alg) {
222+
} else if (!alg || PTR_ERR(alg) == -EEXIST) {
223+
int err = alg ? -EEXIST : -EAGAIN;
224+
225+
/*
226+
* EEXIST is expected because two probes can be scheduled
227+
* at the same time with one using alg_name and the other
228+
* using driver_name. Do a re-lookup but do not retry in
229+
* case we hit a quirk like gcm_base(ctr(aes),...) which
230+
* will never match.
231+
*/
223232
alg = &larval->alg;
224233
alg = crypto_alg_lookup(alg->cra_name, type, mask) ?:
225-
ERR_PTR(-EAGAIN);
234+
ERR_PTR(err);
226235
} else if (IS_ERR(alg))
227236
;
228237
else if (crypto_is_test_larval(larval) &&

0 commit comments

Comments
 (0)