Skip to content

Commit a760a66

Browse files
committed
crypto: api - Fix module load deadlock with fallback algorithms
With the mandatory algorithm testing at registration, we have now created a deadlock with algorithms requiring fallbacks. This can happen if the module containing the algorithm requiring fallback is loaded first, without the fallback module being loaded first. The system will then try to test the new algorithm, find that it needs to load a fallback, and then try to load that. As both algorithms share the same module alias, it can attempt to load the original algorithm again and block indefinitely. As algorithms requiring fallbacks are a special case, we can fix this by giving them a different module alias than the rest. Then it's just a matter of using the right aliases according to what algorithms we're trying to find. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent bb402f1 commit a760a66

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎arch/s390/crypto/aes_s390.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ static void __exit aes_s390_fini(void)
556556
module_init(aes_s390_init);
557557
module_exit(aes_s390_fini);
558558

559-
MODULE_ALIAS("aes");
559+
MODULE_ALIAS("aes-all");
560560

561561
MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
562562
MODULE_LICENSE("GPL");

‎crypto/api.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,19 @@ struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask)
215215
mask &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD);
216216
type &= mask;
217217

218-
alg = try_then_request_module(crypto_alg_lookup(name, type, mask),
219-
name);
218+
alg = crypto_alg_lookup(name, type, mask);
219+
if (!alg) {
220+
char tmp[CRYPTO_MAX_ALG_NAME];
221+
222+
request_module(name);
223+
224+
if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask) &&
225+
snprintf(tmp, sizeof(tmp), "%s-all", name) < sizeof(tmp))
226+
request_module(tmp);
227+
228+
alg = crypto_alg_lookup(name, type, mask);
229+
}
230+
220231
if (alg)
221232
return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
222233

‎drivers/crypto/padlock-aes.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,4 @@ MODULE_DESCRIPTION("VIA PadLock AES algorithm support");
489489
MODULE_LICENSE("GPL");
490490
MODULE_AUTHOR("Michal Ludvig");
491491

492-
MODULE_ALIAS("aes");
492+
MODULE_ALIAS("aes-all");

‎drivers/crypto/padlock-sha.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ MODULE_DESCRIPTION("VIA PadLock SHA1/SHA256 algorithms support.");
304304
MODULE_LICENSE("GPL");
305305
MODULE_AUTHOR("Michal Ludvig");
306306

307-
MODULE_ALIAS("sha1");
308-
MODULE_ALIAS("sha256");
307+
MODULE_ALIAS("sha1-all");
308+
MODULE_ALIAS("sha256-all");
309309
MODULE_ALIAS("sha1-padlock");
310310
MODULE_ALIAS("sha256-padlock");

0 commit comments

Comments
 (0)