fix CVE-2024-13176
This commit is contained in:
parent
cca2e0a5f0
commit
8d6bb4fe33
124
backport-CVE-2024-13176-Fix-timing-side-channel.patch
Normal file
124
backport-CVE-2024-13176-Fix-timing-side-channel.patch
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
From 2af62e74fb59bc469506bc37eb2990ea408d9467 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Tomas Mraz <tomas@openssl.org>
|
||||||
|
Date: Wed, 15 Jan 2025 18:27:02 +0100
|
||||||
|
Subject: [PATCH] Fix timing side-channel in ECDSA signature computation
|
||||||
|
|
||||||
|
There is a timing signal of around 300 nanoseconds when the top word of
|
||||||
|
the inverted ECDSA nonce value is zero. This can happen with significant
|
||||||
|
probability only for some of the supported elliptic curves. In particular
|
||||||
|
the NIST P-521 curve is affected. To be able to measure this leak, the
|
||||||
|
attacker process must either be located in the same physical computer or
|
||||||
|
must have a very fast network connection with low latency.
|
||||||
|
|
||||||
|
Attacks on ECDSA nonce are also known as Minerva attack.
|
||||||
|
|
||||||
|
Fixes CVE-2024-13176
|
||||||
|
|
||||||
|
Reviewed-by: Tim Hudson <tjh@openssl.org>
|
||||||
|
Reviewed-by: Neil Horman <nhorman@openssl.org>
|
||||||
|
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
|
||||||
|
(Merged from https://github.com/openssl/openssl/pull/26429)
|
||||||
|
|
||||||
|
(cherry picked from commit 63c40a66c5dc287485705d06122d3a6e74a6a203)
|
||||||
|
---
|
||||||
|
crypto/bn/bn_exp.c | 21 +++++++++++++++------
|
||||||
|
crypto/ec/ec_lib.c | 7 ++++---
|
||||||
|
include/crypto/bn.h | 3 +++
|
||||||
|
3 files changed, 22 insertions(+), 9 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c
|
||||||
|
index 8700a25a14..9466e53bef 100644
|
||||||
|
--- a/crypto/bn/bn_exp.c
|
||||||
|
+++ b/crypto/bn/bn_exp.c
|
||||||
|
@@ -606,7 +606,7 @@ static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top,
|
||||||
|
* out by Colin Percival,
|
||||||
|
* http://www.daemonology.net/hyperthreading-considered-harmful/)
|
||||||
|
*/
|
||||||
|
-int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
+int bn_mod_exp_mont_fixed_top(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
const BIGNUM *m, BN_CTX *ctx,
|
||||||
|
BN_MONT_CTX *in_mont)
|
||||||
|
{
|
||||||
|
@@ -623,10 +623,6 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
unsigned int t4 = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
- bn_check_top(a);
|
||||||
|
- bn_check_top(p);
|
||||||
|
- bn_check_top(m);
|
||||||
|
-
|
||||||
|
if (!BN_is_odd(m)) {
|
||||||
|
ERR_raise(ERR_LIB_BN, BN_R_CALLED_WITH_EVEN_MODULUS);
|
||||||
|
return 0;
|
||||||
|
@@ -1146,7 +1142,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
goto err;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
- if (!BN_from_montgomery(rr, &tmp, mont, ctx))
|
||||||
|
+ if (!bn_from_mont_fixed_top(rr, &tmp, mont, ctx))
|
||||||
|
goto err;
|
||||||
|
ret = 1;
|
||||||
|
err:
|
||||||
|
@@ -1160,6 +1156,19 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
+int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
+ const BIGNUM *m, BN_CTX *ctx,
|
||||||
|
+ BN_MONT_CTX *in_mont)
|
||||||
|
+{
|
||||||
|
+ bn_check_top(a);
|
||||||
|
+ bn_check_top(p);
|
||||||
|
+ bn_check_top(m);
|
||||||
|
+ if (!bn_mod_exp_mont_fixed_top(rr, a, p, m, ctx, in_mont))
|
||||||
|
+ return 0;
|
||||||
|
+ bn_correct_top(rr);
|
||||||
|
+ return 1;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
|
||||||
|
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
|
||||||
|
{
|
||||||
|
diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c
|
||||||
|
index a84e088c19..eda5c83e55 100644
|
||||||
|
--- a/crypto/ec/ec_lib.c
|
||||||
|
+++ b/crypto/ec/ec_lib.c
|
||||||
|
@@ -20,6 +20,7 @@
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/opensslv.h>
|
||||||
|
#include "crypto/ec.h"
|
||||||
|
+#include "crypto/bn.h"
|
||||||
|
#include "internal/nelem.h"
|
||||||
|
#include "ec_local.h"
|
||||||
|
|
||||||
|
@@ -1262,10 +1263,10 @@ static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r,
|
||||||
|
if (!BN_sub(e, group->order, e))
|
||||||
|
goto err;
|
||||||
|
/*-
|
||||||
|
- * Exponent e is public.
|
||||||
|
- * No need for scatter-gather or BN_FLG_CONSTTIME.
|
||||||
|
+ * Although the exponent is public we want the result to be
|
||||||
|
+ * fixed top.
|
||||||
|
*/
|
||||||
|
- if (!BN_mod_exp_mont(r, x, e, group->order, ctx, group->mont_data))
|
||||||
|
+ if (!bn_mod_exp_mont_fixed_top(r, x, e, group->order, ctx, group->mont_data))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
diff --git a/include/crypto/bn.h b/include/crypto/bn.h
|
||||||
|
index f8855d8463..34244bdf1a 100644
|
||||||
|
--- a/include/crypto/bn.h
|
||||||
|
+++ b/include/crypto/bn.h
|
||||||
|
@@ -73,6 +73,9 @@ int bn_set_words(BIGNUM *a, const BN_ULONG *words, int num_words);
|
||||||
|
*/
|
||||||
|
int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||||
|
BN_MONT_CTX *mont, BN_CTX *ctx);
|
||||||
|
+int bn_mod_exp_mont_fixed_top(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||||
|
+ const BIGNUM *m, BN_CTX *ctx,
|
||||||
|
+ BN_MONT_CTX *in_mont);
|
||||||
|
int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
|
||||||
|
BN_CTX *ctx);
|
||||||
|
int bn_from_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
Name: openssl
|
Name: openssl
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
Version: 3.0.12
|
Version: 3.0.12
|
||||||
Release: 15
|
Release: 16
|
||||||
Summary: Cryptography and SSL/TLS Toolkit
|
Summary: Cryptography and SSL/TLS Toolkit
|
||||||
License: OpenSSL and SSLeay
|
License: OpenSSL and SSLeay
|
||||||
URL: https://www.openssl.org/
|
URL: https://www.openssl.org/
|
||||||
@ -75,6 +75,7 @@ Patch62: backport-Refactor-a-separate-func-for-provider-activation-fro.patch
|
|||||||
Patch63: backport-Refactor-OSSL_LIB_CTX-to-avoid-using-CRYPTO_EX_DATA.patch
|
Patch63: backport-Refactor-OSSL_LIB_CTX-to-avoid-using-CRYPTO_EX_DATA.patch
|
||||||
Patch64: backport-Release-the-drbg-in-the-global-default-context-befor.patch
|
Patch64: backport-Release-the-drbg-in-the-global-default-context-befor.patch
|
||||||
Patch65: backport-params-provide-a-faster-TRIE-based-param-lookup.patch
|
Patch65: backport-params-provide-a-faster-TRIE-based-param-lookup.patch
|
||||||
|
Patch66: backport-CVE-2024-13176-Fix-timing-side-channel.patch
|
||||||
|
|
||||||
Patch9000: add-FIPS_mode_set-support.patch
|
Patch9000: add-FIPS_mode_set-support.patch
|
||||||
Patch9001: backport-CVE-2024-9143-Harden-BN_GF2m_poly2arr-against-misuse.patch
|
Patch9001: backport-CVE-2024-9143-Harden-BN_GF2m_poly2arr-against-misuse.patch
|
||||||
@ -279,6 +280,9 @@ make test || :
|
|||||||
%ldconfig_scriptlets libs
|
%ldconfig_scriptlets libs
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sat Feb 8 2025 jinlun <jinlun@huawei.com> - 1:3.0.12-16
|
||||||
|
- fix CVE-2024-13176
|
||||||
|
|
||||||
* Wed Nov 27 2024 steven <steven_ygui@163.com> - 1:3.0.12-15
|
* Wed Nov 27 2024 steven <steven_ygui@163.com> - 1:3.0.12-15
|
||||||
- backport patch for performance improvements
|
- backport patch for performance improvements
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user