Skip to content

Commit

Permalink
crypto: run initcalls for generic implementations earlier
Browse files Browse the repository at this point in the history
Use subsys_initcall for registration of all templates and generic
algorithm implementations, rather than module_init.  Then change
cryptomgr to use arch_initcall, to place it before the subsys_initcalls.

This is needed so that when both a generic and optimized implementation
of an algorithm are built into the kernel (not loadable modules), the
generic implementation is registered before the optimized one.
Otherwise, the self-tests for the optimized implementation are unable to
allocate the generic implementation for the new comparison fuzz tests.

Note that on arm, a side effect of this change is that self-tests for
generic implementations may run before the unaligned access handler has
been installed.  So, unaligned accesses will crash the kernel.  This is
arguably a good thing as it makes it easier to detect that type of bug.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
ebiggers authored and herbertx committed Apr 18, 2019
1 parent 40153b1 commit c4741b2
Show file tree
Hide file tree
Showing 83 changed files with 89 additions and 83 deletions.
2 changes: 1 addition & 1 deletion crypto/842.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static int __init crypto842_mod_init(void)

return ret;
}
module_init(crypto842_mod_init);
subsys_initcall(crypto842_mod_init);

static void __exit crypto842_mod_exit(void)
{
Expand Down
2 changes: 1 addition & 1 deletion crypto/adiantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static void __exit adiantum_module_exit(void)
crypto_unregister_template(&adiantum_tmpl);
}

module_init(adiantum_module_init);
subsys_initcall(adiantum_module_init);
module_exit(adiantum_module_exit);

MODULE_DESCRIPTION("Adiantum length-preserving encryption mode");
Expand Down
2 changes: 1 addition & 1 deletion crypto/aegis128.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static void __exit crypto_aegis128_module_exit(void)
crypto_unregister_aead(&crypto_aegis128_alg);
}

module_init(crypto_aegis128_module_init);
subsys_initcall(crypto_aegis128_module_init);
module_exit(crypto_aegis128_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/aegis128l.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static void __exit crypto_aegis128l_module_exit(void)
crypto_unregister_aead(&crypto_aegis128l_alg);
}

module_init(crypto_aegis128l_module_init);
subsys_initcall(crypto_aegis128l_module_init);
module_exit(crypto_aegis128l_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/aegis256.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static void __exit crypto_aegis256_module_exit(void)
crypto_unregister_aead(&crypto_aegis256_alg);
}

module_init(crypto_aegis256_module_init);
subsys_initcall(crypto_aegis256_module_init);
module_exit(crypto_aegis256_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/aes_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ static void __exit aes_fini(void)
crypto_unregister_alg(&aes_alg);
}

module_init(aes_init);
subsys_initcall(aes_init);
module_exit(aes_fini);

MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
Expand Down
8 changes: 7 additions & 1 deletion crypto/algboss.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ static void __exit cryptomgr_exit(void)
BUG_ON(err);
}

subsys_initcall(cryptomgr_init);
/*
* This is arch_initcall() so that the crypto self-tests are run on algorithms
* registered early by subsys_initcall(). subsys_initcall() is needed for
* generic implementations so that they're available for comparison tests when
* other implementations are registered later by module_init().
*/
arch_initcall(cryptomgr_init);
module_exit(cryptomgr_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/ansi_cprng.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ MODULE_DESCRIPTION("Software Pseudo Random Number Generator");
MODULE_AUTHOR("Neil Horman <nhorman@tuxdriver.com>");
module_param(dbg, int, 0);
MODULE_PARM_DESC(dbg, "Boolean to enable debugging (0/1 == off/on)");
module_init(prng_mod_init);
subsys_initcall(prng_mod_init);
module_exit(prng_mod_fini);
MODULE_ALIAS_CRYPTO("stdrng");
MODULE_ALIAS_CRYPTO("ansi_cprng");
2 changes: 1 addition & 1 deletion crypto/anubis.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ static void __exit anubis_mod_fini(void)
crypto_unregister_alg(&anubis_alg);
}

module_init(anubis_mod_init);
subsys_initcall(anubis_mod_init);
module_exit(anubis_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/arc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static void __exit arc4_exit(void)
crypto_unregister_skcipher(&arc4_skcipher);
}

module_init(arc4_init);
subsys_initcall(arc4_init);
module_exit(arc4_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/authenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static void __exit crypto_authenc_module_exit(void)
crypto_unregister_template(&crypto_authenc_tmpl);
}

module_init(crypto_authenc_module_init);
subsys_initcall(crypto_authenc_module_init);
module_exit(crypto_authenc_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/authencesn.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ static void __exit crypto_authenc_esn_module_exit(void)
crypto_unregister_template(&crypto_authenc_esn_tmpl);
}

module_init(crypto_authenc_esn_module_init);
subsys_initcall(crypto_authenc_esn_module_init);
module_exit(crypto_authenc_esn_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/blowfish_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static void __exit blowfish_mod_fini(void)
crypto_unregister_alg(&alg);
}

module_init(blowfish_mod_init);
subsys_initcall(blowfish_mod_init);
module_exit(blowfish_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/camellia_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ static void __exit camellia_fini(void)
crypto_unregister_alg(&camellia_alg);
}

module_init(camellia_init);
subsys_initcall(camellia_init);
module_exit(camellia_fini);

MODULE_DESCRIPTION("Camellia Cipher Algorithm");
Expand Down
2 changes: 1 addition & 1 deletion crypto/cast5_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ static void __exit cast5_mod_fini(void)
crypto_unregister_alg(&alg);
}

module_init(cast5_mod_init);
subsys_initcall(cast5_mod_init);
module_exit(cast5_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/cast6_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static void __exit cast6_mod_fini(void)
crypto_unregister_alg(&alg);
}

module_init(cast6_mod_init);
subsys_initcall(cast6_mod_init);
module_exit(cast6_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/cbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void __exit crypto_cbc_module_exit(void)
crypto_unregister_template(&crypto_cbc_tmpl);
}

module_init(crypto_cbc_module_init);
subsys_initcall(crypto_cbc_module_init);
module_exit(crypto_cbc_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ static void __exit crypto_ccm_module_exit(void)
ARRAY_SIZE(crypto_ccm_tmpls));
}

module_init(crypto_ccm_module_init);
subsys_initcall(crypto_ccm_module_init);
module_exit(crypto_ccm_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/cfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static void __exit crypto_cfb_module_exit(void)
crypto_unregister_template(&crypto_cfb_tmpl);
}

module_init(crypto_cfb_module_init);
subsys_initcall(crypto_cfb_module_init);
module_exit(crypto_cfb_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/chacha20poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ static void __exit chacha20poly1305_module_exit(void)
ARRAY_SIZE(rfc7539_tmpls));
}

module_init(chacha20poly1305_module_init);
subsys_initcall(chacha20poly1305_module_init);
module_exit(chacha20poly1305_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/chacha_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void __exit chacha_generic_mod_fini(void)
crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
}

module_init(chacha_generic_mod_init);
subsys_initcall(chacha_generic_mod_init);
module_exit(chacha_generic_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/cmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static void __exit crypto_cmac_module_exit(void)
crypto_unregister_template(&crypto_cmac_tmpl);
}

module_init(crypto_cmac_module_init);
subsys_initcall(crypto_cmac_module_init);
module_exit(crypto_cmac_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/crc32_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static void __exit crc32_mod_fini(void)
crypto_unregister_shash(&alg);
}

module_init(crc32_mod_init);
subsys_initcall(crc32_mod_init);
module_exit(crc32_mod_fini);

MODULE_AUTHOR("Alexander Boyko <alexander_boyko@xyratex.com>");
Expand Down
2 changes: 1 addition & 1 deletion crypto/crc32c_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void __exit crc32c_mod_fini(void)
crypto_unregister_shash(&alg);
}

module_init(crc32c_mod_init);
subsys_initcall(crc32c_mod_init);
module_exit(crc32c_mod_fini);

MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
Expand Down
2 changes: 1 addition & 1 deletion crypto/crct10dif_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void __exit crct10dif_mod_fini(void)
crypto_unregister_shash(&alg);
}

module_init(crct10dif_mod_init);
subsys_initcall(crct10dif_mod_init);
module_exit(crct10dif_mod_fini);

MODULE_AUTHOR("Tim Chen <tim.c.chen@linux.intel.com>");
Expand Down
2 changes: 1 addition & 1 deletion crypto/crypto_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static void __exit crypto_null_mod_fini(void)
crypto_unregister_skcipher(&skcipher_null);
}

module_init(crypto_null_mod_init);
subsys_initcall(crypto_null_mod_init);
module_exit(crypto_null_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/ctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static void __exit crypto_ctr_module_exit(void)
ARRAY_SIZE(crypto_ctr_tmpls));
}

module_init(crypto_ctr_module_init);
subsys_initcall(crypto_ctr_module_init);
module_exit(crypto_ctr_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/cts.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static void __exit crypto_cts_module_exit(void)
crypto_unregister_template(&crypto_cts_tmpl);
}

module_init(crypto_cts_module_init);
subsys_initcall(crypto_cts_module_init);
module_exit(crypto_cts_module_exit);

MODULE_LICENSE("Dual BSD/GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static void __exit deflate_mod_fini(void)
crypto_unregister_scomps(scomp, ARRAY_SIZE(scomp));
}

module_init(deflate_mod_init);
subsys_initcall(deflate_mod_init);
module_exit(deflate_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/des_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ static void __exit des_generic_mod_fini(void)
crypto_unregister_algs(des_algs, ARRAY_SIZE(des_algs));
}

module_init(des_generic_mod_init);
subsys_initcall(des_generic_mod_init);
module_exit(des_generic_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static void dh_exit(void)
crypto_unregister_kpp(&dh);
}

module_init(dh_init);
subsys_initcall(dh_init);
module_exit(dh_exit);
MODULE_ALIAS_CRYPTO("dh");
MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ static void __exit drbg_exit(void)
crypto_unregister_rngs(drbg_algs, (ARRAY_SIZE(drbg_cores) * 2));
}

module_init(drbg_init);
subsys_initcall(drbg_init);
module_exit(drbg_exit);
#ifndef CRYPTO_DRBG_HASH_STRING
#define CRYPTO_DRBG_HASH_STRING ""
Expand Down
2 changes: 1 addition & 1 deletion crypto/ecb.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void __exit crypto_ecb_module_exit(void)
crypto_unregister_template(&crypto_ecb_tmpl);
}

module_init(crypto_ecb_module_init);
subsys_initcall(crypto_ecb_module_init);
module_exit(crypto_ecb_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static void ecdh_exit(void)
crypto_unregister_kpp(&ecdh);
}

module_init(ecdh_init);
subsys_initcall(ecdh_init);
module_exit(ecdh_exit);
MODULE_ALIAS_CRYPTO("ecdh");
MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/echainiv.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static void __exit echainiv_module_exit(void)
crypto_unregister_template(&echainiv_tmpl);
}

module_init(echainiv_module_init);
subsys_initcall(echainiv_module_init);
module_exit(echainiv_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/fcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ static void __exit fcrypt_mod_fini(void)
crypto_unregister_alg(&fcrypt_alg);
}

module_init(fcrypt_mod_init);
subsys_initcall(fcrypt_mod_init);
module_exit(fcrypt_mod_fini);

MODULE_LICENSE("Dual BSD/GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/fips.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ static void __exit fips_exit(void)
crypto_proc_fips_exit();
}

module_init(fips_init);
subsys_initcall(fips_init);
module_exit(fips_exit);
2 changes: 1 addition & 1 deletion crypto/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ static void __exit crypto_gcm_module_exit(void)
ARRAY_SIZE(crypto_gcm_tmpls));
}

module_init(crypto_gcm_module_init);
subsys_initcall(crypto_gcm_module_init);
module_exit(crypto_gcm_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/ghash-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void __exit ghash_mod_exit(void)
crypto_unregister_shash(&ghash_alg);
}

module_init(ghash_mod_init);
subsys_initcall(ghash_mod_init);
module_exit(ghash_mod_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static void __exit hmac_module_exit(void)
crypto_unregister_template(&hmac_tmpl);
}

module_init(hmac_module_init);
subsys_initcall(hmac_module_init);
module_exit(hmac_module_exit);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/jitterentropy-kcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static void __exit jent_mod_exit(void)
crypto_unregister_rng(&jent_alg);
}

module_init(jent_mod_init);
subsys_initcall(jent_mod_init);
module_exit(jent_mod_exit);

MODULE_LICENSE("Dual BSD/GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/keywrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static void __exit crypto_kw_exit(void)
crypto_unregister_template(&crypto_kw_tmpl);
}

module_init(crypto_kw_init);
subsys_initcall(crypto_kw_init);
module_exit(crypto_kw_exit);

MODULE_LICENSE("Dual BSD/GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/khazad.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ static void __exit khazad_mod_fini(void)
}


module_init(khazad_mod_init);
subsys_initcall(khazad_mod_init);
module_exit(khazad_mod_fini);

MODULE_LICENSE("GPL");
Expand Down
2 changes: 1 addition & 1 deletion crypto/lrw.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ static void __exit crypto_module_exit(void)
crypto_unregister_template(&crypto_tmpl);
}

module_init(crypto_module_init);
subsys_initcall(crypto_module_init);
module_exit(crypto_module_exit);

MODULE_LICENSE("GPL");
Expand Down
Loading

0 comments on commit c4741b2

Please sign in to comment.