Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+17 -6
+1 -1
arch/s390/crypto/aes_s390.c
··· 556 556 module_init(aes_s390_init); 557 557 module_exit(aes_s390_fini); 558 558 559 - MODULE_ALIAS("aes"); 559 + MODULE_ALIAS("aes-all"); 560 560 561 561 MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm"); 562 562 MODULE_LICENSE("GPL");
+13 -2
crypto/api.c
··· 215 215 mask &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD); 216 216 type &= mask; 217 217 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 + 220 231 if (alg) 221 232 return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg; 222 233
+1 -1
drivers/crypto/padlock-aes.c
··· 489 489 MODULE_LICENSE("GPL"); 490 490 MODULE_AUTHOR("Michal Ludvig"); 491 491 492 - MODULE_ALIAS("aes"); 492 + MODULE_ALIAS("aes-all");
+2 -2
drivers/crypto/padlock-sha.c
··· 304 304 MODULE_LICENSE("GPL"); 305 305 MODULE_AUTHOR("Michal Ludvig"); 306 306 307 - MODULE_ALIAS("sha1"); 308 - MODULE_ALIAS("sha256"); 307 + MODULE_ALIAS("sha1-all"); 308 + MODULE_ALIAS("sha256-all"); 309 309 MODULE_ALIAS("sha1-padlock"); 310 310 MODULE_ALIAS("sha256-padlock");