Skip to content

Commit 877ccce

Browse files
WOnder93herbertx
authored andcommitted
crypto: x86/aegis,morus - Fix and simplify CPUID checks
It turns out I had misunderstood how the x86_match_cpu() function works. It evaluates a logical OR of the matching conditions, not logical AND. This caused the CPU feature checks for AEGIS to pass even if only SSE2 (but not AES-NI) was supported (or vice versa), leading to potential crashes if something tried to use the registered algs. This patch switches the checks to a simpler method that is used e.g. in the Camellia x86 code. The patch also removes the MODULE_DEVICE_TABLE declarations which actually seem to cause the modules to be auto-loaded at boot, which is not desired. The crypto API on-demand module loading is sufficient. Fixes: 1d373d4 ("crypto: x86 - Add optimized AEGIS implementations") Fixes: 6ecc9d9 ("crypto: x86 - Add optimized MORUS implementations") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Tested-by: Milan Broz <gmazyland@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f10dc56 commit 877ccce

File tree

6 files changed

+21
-45
lines changed

6 files changed

+21
-45
lines changed

arch/x86/crypto/aegis128-aesni-glue.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,12 @@ static struct aead_alg crypto_aegis128_aesni_alg[] = {
375375
}
376376
};
377377

378-
static const struct x86_cpu_id aesni_cpu_id[] = {
379-
X86_FEATURE_MATCH(X86_FEATURE_AES),
380-
X86_FEATURE_MATCH(X86_FEATURE_XMM2),
381-
{}
382-
};
383-
MODULE_DEVICE_TABLE(x86cpu, aesni_cpu_id);
384-
385378
static int __init crypto_aegis128_aesni_module_init(void)
386379
{
387-
if (!x86_match_cpu(aesni_cpu_id))
380+
if (!boot_cpu_has(X86_FEATURE_XMM2) ||
381+
!boot_cpu_has(X86_FEATURE_AES) ||
382+
!boot_cpu_has(X86_FEATURE_OSXSAVE) ||
383+
!cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
388384
return -ENODEV;
389385

390386
return crypto_register_aeads(crypto_aegis128_aesni_alg,

arch/x86/crypto/aegis128l-aesni-glue.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,12 @@ static struct aead_alg crypto_aegis128l_aesni_alg[] = {
375375
}
376376
};
377377

378-
static const struct x86_cpu_id aesni_cpu_id[] = {
379-
X86_FEATURE_MATCH(X86_FEATURE_AES),
380-
X86_FEATURE_MATCH(X86_FEATURE_XMM2),
381-
{}
382-
};
383-
MODULE_DEVICE_TABLE(x86cpu, aesni_cpu_id);
384-
385378
static int __init crypto_aegis128l_aesni_module_init(void)
386379
{
387-
if (!x86_match_cpu(aesni_cpu_id))
380+
if (!boot_cpu_has(X86_FEATURE_XMM2) ||
381+
!boot_cpu_has(X86_FEATURE_AES) ||
382+
!boot_cpu_has(X86_FEATURE_OSXSAVE) ||
383+
!cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
388384
return -ENODEV;
389385

390386
return crypto_register_aeads(crypto_aegis128l_aesni_alg,

arch/x86/crypto/aegis256-aesni-glue.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,12 @@ static struct aead_alg crypto_aegis256_aesni_alg[] = {
375375
}
376376
};
377377

378-
static const struct x86_cpu_id aesni_cpu_id[] = {
379-
X86_FEATURE_MATCH(X86_FEATURE_AES),
380-
X86_FEATURE_MATCH(X86_FEATURE_XMM2),
381-
{}
382-
};
383-
MODULE_DEVICE_TABLE(x86cpu, aesni_cpu_id);
384-
385378
static int __init crypto_aegis256_aesni_module_init(void)
386379
{
387-
if (!x86_match_cpu(aesni_cpu_id))
380+
if (!boot_cpu_has(X86_FEATURE_XMM2) ||
381+
!boot_cpu_has(X86_FEATURE_AES) ||
382+
!boot_cpu_has(X86_FEATURE_OSXSAVE) ||
383+
!cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
388384
return -ENODEV;
389385

390386
return crypto_register_aeads(crypto_aegis256_aesni_alg,

arch/x86/crypto/morus1280-avx2-glue.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ asmlinkage void crypto_morus1280_avx2_final(void *state, void *tag_xor,
3737

3838
MORUS1280_DECLARE_ALGS(avx2, "morus1280-avx2", 400);
3939

40-
static const struct x86_cpu_id avx2_cpu_id[] = {
41-
X86_FEATURE_MATCH(X86_FEATURE_AVX2),
42-
{}
43-
};
44-
MODULE_DEVICE_TABLE(x86cpu, avx2_cpu_id);
45-
4640
static int __init crypto_morus1280_avx2_module_init(void)
4741
{
48-
if (!x86_match_cpu(avx2_cpu_id))
42+
if (!boot_cpu_has(X86_FEATURE_AVX2) ||
43+
!boot_cpu_has(X86_FEATURE_OSXSAVE) ||
44+
!cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL))
4945
return -ENODEV;
5046

5147
return crypto_register_aeads(crypto_morus1280_avx2_algs,

arch/x86/crypto/morus1280-sse2-glue.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ asmlinkage void crypto_morus1280_sse2_final(void *state, void *tag_xor,
3737

3838
MORUS1280_DECLARE_ALGS(sse2, "morus1280-sse2", 350);
3939

40-
static const struct x86_cpu_id sse2_cpu_id[] = {
41-
X86_FEATURE_MATCH(X86_FEATURE_XMM2),
42-
{}
43-
};
44-
MODULE_DEVICE_TABLE(x86cpu, sse2_cpu_id);
45-
4640
static int __init crypto_morus1280_sse2_module_init(void)
4741
{
48-
if (!x86_match_cpu(sse2_cpu_id))
42+
if (!boot_cpu_has(X86_FEATURE_XMM2) ||
43+
!boot_cpu_has(X86_FEATURE_OSXSAVE) ||
44+
!cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
4945
return -ENODEV;
5046

5147
return crypto_register_aeads(crypto_morus1280_sse2_algs,

arch/x86/crypto/morus640-sse2-glue.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ asmlinkage void crypto_morus640_sse2_final(void *state, void *tag_xor,
3737

3838
MORUS640_DECLARE_ALGS(sse2, "morus640-sse2", 400);
3939

40-
static const struct x86_cpu_id sse2_cpu_id[] = {
41-
X86_FEATURE_MATCH(X86_FEATURE_XMM2),
42-
{}
43-
};
44-
MODULE_DEVICE_TABLE(x86cpu, sse2_cpu_id);
45-
4640
static int __init crypto_morus640_sse2_module_init(void)
4741
{
48-
if (!x86_match_cpu(sse2_cpu_id))
42+
if (!boot_cpu_has(X86_FEATURE_XMM2) ||
43+
!boot_cpu_has(X86_FEATURE_OSXSAVE) ||
44+
!cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
4945
return -ENODEV;
5046

5147
return crypto_register_aeads(crypto_morus640_sse2_algs,

0 commit comments

Comments
 (0)