Commit a760a6656e6f00bb0144a42a048cf0266646e22c
1 parent
bb402f16ec
Exists in
master
and in
20 other branches
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>
Showing 4 changed files with 17 additions and 6 deletions Side-by-side Diff
arch/s390/crypto/aes_s390.c
crypto/api.c
| ... | ... | @@ -215,8 +215,19 @@ |
| 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 |
drivers/crypto/padlock-aes.c
drivers/crypto/padlock-sha.c
| ... | ... | @@ -304,8 +304,8 @@ |
| 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"); |