* [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit
@ 2021-06-03 5:53 Hangbin Liu
2021-06-03 10:24 ` Jason A. Donenfeld
2021-06-11 7:23 ` Herbert Xu
0 siblings, 2 replies; 6+ messages in thread
From: Hangbin Liu @ 2021-06-03 5:53 UTC (permalink / raw)
To: linux-crypto; +Cc: Jason A . Donenfeld, Herbert Xu, netdev, Hangbin Liu
In curve25519_mod_init() the curve25519_alg will be registered only when
(X86_FEATURE_BMI2 && X86_FEATURE_ADX). But in curve25519_mod_exit()
it still checks (X86_FEATURE_BMI2 || X86_FEATURE_ADX) when do crypto
unregister. This will trigger a BUG_ON in crypto_unregister_alg() as
alg->cra_refcnt is 0 if the cpu only supports one of X86_FEATURE_BMI2
and X86_FEATURE_ADX.
Fixes: 07b586fe0662 ("crypto: x86/curve25519 - replace with formally verified implementation")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
arch/x86/crypto/curve25519-x86_64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/crypto/curve25519-x86_64.c b/arch/x86/crypto/curve25519-x86_64.c
index 6706b6cb1d0f..38caf61cd5b7 100644
--- a/arch/x86/crypto/curve25519-x86_64.c
+++ b/arch/x86/crypto/curve25519-x86_64.c
@@ -1500,7 +1500,7 @@ static int __init curve25519_mod_init(void)
static void __exit curve25519_mod_exit(void)
{
if (IS_REACHABLE(CONFIG_CRYPTO_KPP) &&
- (boot_cpu_has(X86_FEATURE_BMI2) || boot_cpu_has(X86_FEATURE_ADX)))
+ static_branch_likely(&curve25519_use_bmi2_adx))
crypto_unregister_kpp(&curve25519_alg);
}
--
2.26.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit
2021-06-03 5:53 [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit Hangbin Liu
@ 2021-06-03 10:24 ` Jason A. Donenfeld
2021-06-03 14:06 ` Hangbin Liu
2021-06-11 7:23 ` Herbert Xu
1 sibling, 1 reply; 6+ messages in thread
From: Jason A. Donenfeld @ 2021-06-03 10:24 UTC (permalink / raw)
To: Hangbin Liu; +Cc: Linux Crypto Mailing List, Herbert Xu, Netdev, stable
On Thu, Jun 3, 2021 at 7:53 AM Hangbin Liu <liuhangbin@gmail.com> wrote:
>
> In curve25519_mod_init() the curve25519_alg will be registered only when
> (X86_FEATURE_BMI2 && X86_FEATURE_ADX). But in curve25519_mod_exit()
> it still checks (X86_FEATURE_BMI2 || X86_FEATURE_ADX) when do crypto
> unregister. This will trigger a BUG_ON in crypto_unregister_alg() as
> alg->cra_refcnt is 0 if the cpu only supports one of X86_FEATURE_BMI2
> and X86_FEATURE_ADX.
>
> Fixes: 07b586fe0662 ("crypto: x86/curve25519 - replace with formally verified implementation")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> arch/x86/crypto/curve25519-x86_64.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/crypto/curve25519-x86_64.c b/arch/x86/crypto/curve25519-x86_64.c
> index 6706b6cb1d0f..38caf61cd5b7 100644
> --- a/arch/x86/crypto/curve25519-x86_64.c
> +++ b/arch/x86/crypto/curve25519-x86_64.c
> @@ -1500,7 +1500,7 @@ static int __init curve25519_mod_init(void)
> static void __exit curve25519_mod_exit(void)
> {
> if (IS_REACHABLE(CONFIG_CRYPTO_KPP) &&
> - (boot_cpu_has(X86_FEATURE_BMI2) || boot_cpu_has(X86_FEATURE_ADX)))
> + static_branch_likely(&curve25519_use_bmi2_adx))
> crypto_unregister_kpp(&curve25519_alg);
> }
Looks like the error is actually that the `||` should be a `&&`. But
if you'd like to branch on that static key instead, that's fine.
Cc: stable@vger.kernel.org
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit
2021-06-03 10:24 ` Jason A. Donenfeld
@ 2021-06-03 14:06 ` Hangbin Liu
0 siblings, 0 replies; 6+ messages in thread
From: Hangbin Liu @ 2021-06-03 14:06 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Linux Crypto Mailing List, Herbert Xu, Netdev, stable
On Thu, Jun 3, 2021 at 6:24 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> > if (IS_REACHABLE(CONFIG_CRYPTO_KPP) &&
> > - (boot_cpu_has(X86_FEATURE_BMI2) || boot_cpu_has(X86_FEATURE_ADX)))
> > + static_branch_likely(&curve25519_use_bmi2_adx))
> > crypto_unregister_kpp(&curve25519_alg);
> > }
>
> Looks like the error is actually that the `||` should be a `&&`. But
> if you'd like to branch on that static key instead, that's fine.
Yes, the code would be shorter by checking the static key :)
Thanks
hangbin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit
2021-06-03 5:53 [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit Hangbin Liu
2021-06-03 10:24 ` Jason A. Donenfeld
@ 2021-06-11 7:23 ` Herbert Xu
2021-06-11 10:07 ` Jason A. Donenfeld
1 sibling, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2021-06-11 7:23 UTC (permalink / raw)
To: Hangbin Liu; +Cc: linux-crypto, Jason A . Donenfeld, netdev
On Thu, Jun 03, 2021 at 01:53:40AM -0400, Hangbin Liu wrote:
> In curve25519_mod_init() the curve25519_alg will be registered only when
> (X86_FEATURE_BMI2 && X86_FEATURE_ADX). But in curve25519_mod_exit()
> it still checks (X86_FEATURE_BMI2 || X86_FEATURE_ADX) when do crypto
> unregister. This will trigger a BUG_ON in crypto_unregister_alg() as
> alg->cra_refcnt is 0 if the cpu only supports one of X86_FEATURE_BMI2
> and X86_FEATURE_ADX.
>
> Fixes: 07b586fe0662 ("crypto: x86/curve25519 - replace with formally verified implementation")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> arch/x86/crypto/curve25519-x86_64.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-11 12:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 5:53 [PATCH] crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit Hangbin Liu
2021-06-03 10:24 ` Jason A. Donenfeld
2021-06-03 14:06 ` Hangbin Liu
2021-06-11 7:23 ` Herbert Xu
2021-06-11 10:07 ` Jason A. Donenfeld
2021-06-11 12:46 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.