diff options
| -rw-r--r-- | meta/recipes-connectivity/openssl/openssl/0001-Added-handshake-history-reporting-when-test-fails.patch | 40 | ||||
| -rw-r--r-- | meta/recipes-connectivity/openssl/openssl/0001-Configure-do-not-tweak-mips-cflags.patch | 2 | ||||
| -rw-r--r-- | meta/recipes-connectivity/openssl/openssl/0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch | 4 | ||||
| -rw-r--r-- | meta/recipes-connectivity/openssl/openssl/CVE-2024-13176.patch | 126 | ||||
| -rwxr-xr-x | meta/recipes-connectivity/openssl/openssl/CVE-2024-9143.patch | 202 | ||||
| -rw-r--r-- | meta/recipes-connectivity/openssl/openssl_3.2.4.bb (renamed from meta/recipes-connectivity/openssl/openssl_3.2.3.bb) | 4 |
6 files changed, 24 insertions, 354 deletions
diff --git a/meta/recipes-connectivity/openssl/openssl/0001-Added-handshake-history-reporting-when-test-fails.patch b/meta/recipes-connectivity/openssl/openssl/0001-Added-handshake-history-reporting-when-test-fails.patch index 9baa0c2d75..b05d7abf7c 100644 --- a/meta/recipes-connectivity/openssl/openssl/0001-Added-handshake-history-reporting-when-test-fails.patch +++ b/meta/recipes-connectivity/openssl/openssl/0001-Added-handshake-history-reporting-when-test-fails.patch | |||
| @@ -8,10 +8,10 @@ Upstream-Status: Submitted [https://github.com/openssl/openssl/pull/22481] | |||
| 8 | Signed-off-by: William Lyu <William.Lyu@windriver.com> | 8 | Signed-off-by: William Lyu <William.Lyu@windriver.com> |
| 9 | Signed-off-by: Siddharth Doshi <sdoshi@mvista.com> | 9 | Signed-off-by: Siddharth Doshi <sdoshi@mvista.com> |
| 10 | --- | 10 | --- |
| 11 | test/helpers/handshake.c | 139 +++++++++++++++++++++++++++++---------- | 11 | test/helpers/handshake.c | 137 +++++++++++++++++++++++++++++---------- |
| 12 | test/helpers/handshake.h | 70 +++++++++++++++++++- | 12 | test/helpers/handshake.h | 70 +++++++++++++++++++- |
| 13 | test/ssl_test.c | 44 +++++++++++++ | 13 | test/ssl_test.c | 44 +++++++++++++ |
| 14 | 3 files changed, 218 insertions(+), 35 deletions(-) | 14 | 3 files changed, 217 insertions(+), 34 deletions(-) |
| 15 | 15 | ||
| 16 | diff --git a/test/helpers/handshake.c b/test/helpers/handshake.c | 16 | diff --git a/test/helpers/handshake.c b/test/helpers/handshake.c |
| 17 | index e0422469e4..ae2ad59dd4 100644 | 17 | index e0422469e4..ae2ad59dd4 100644 |
| @@ -20,7 +20,7 @@ index e0422469e4..ae2ad59dd4 100644 | |||
| 20 | @@ -24,6 +24,102 @@ | 20 | @@ -24,6 +24,102 @@ |
| 21 | #include <netinet/sctp.h> | 21 | #include <netinet/sctp.h> |
| 22 | #endif | 22 | #endif |
| 23 | 23 | ||
| 24 | +/* Shamelessly copied from test/helpers/ssl_test_ctx.c */ | 24 | +/* Shamelessly copied from test/helpers/ssl_test_ctx.c */ |
| 25 | +/* Maps string names to various enumeration type */ | 25 | +/* Maps string names to various enumeration type */ |
| 26 | +typedef struct { | 26 | +typedef struct { |
| @@ -120,10 +120,10 @@ index e0422469e4..ae2ad59dd4 100644 | |||
| 120 | HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void) | 120 | HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void) |
| 121 | { | 121 | { |
| 122 | HANDSHAKE_RESULT *ret; | 122 | HANDSHAKE_RESULT *ret; |
| 123 | @@ -719,15 +815,6 @@ static void configure_handshake_ssl(SSL *server, SSL *client, | 123 | @@ -725,15 +821,6 @@ static void configure_handshake_ssl(SSL *server, SSL *client, |
| 124 | SSL_set_post_handshake_auth(client, 1); | 124 | SSL_set_post_handshake_auth(client, 1); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | -/* The status for each connection phase. */ | 127 | -/* The status for each connection phase. */ |
| 128 | -typedef enum { | 128 | -typedef enum { |
| 129 | - PEER_SUCCESS, | 129 | - PEER_SUCCESS, |
| @@ -136,10 +136,10 @@ index e0422469e4..ae2ad59dd4 100644 | |||
| 136 | /* An SSL object and associated read-write buffers. */ | 136 | /* An SSL object and associated read-write buffers. */ |
| 137 | typedef struct peer_st { | 137 | typedef struct peer_st { |
| 138 | SSL *ssl; | 138 | SSL *ssl; |
| 139 | @@ -1074,17 +1161,6 @@ static void do_shutdown_step(PEER *peer) | 139 | @@ -1080,17 +1167,6 @@ static void do_shutdown_step(PEER *peer) |
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | -typedef enum { | 143 | -typedef enum { |
| 144 | - HANDSHAKE, | 144 | - HANDSHAKE, |
| 145 | - RENEG_APPLICATION_DATA, | 145 | - RENEG_APPLICATION_DATA, |
| @@ -154,10 +154,10 @@ index e0422469e4..ae2ad59dd4 100644 | |||
| 154 | static int renegotiate_op(const SSL_TEST_CTX *test_ctx) | 154 | static int renegotiate_op(const SSL_TEST_CTX *test_ctx) |
| 155 | { | 155 | { |
| 156 | switch (test_ctx->handshake_mode) { | 156 | switch (test_ctx->handshake_mode) { |
| 157 | @@ -1162,19 +1238,6 @@ static void do_connect_step(const SSL_TEST_CTX *test_ctx, PEER *peer, | 157 | @@ -1168,19 +1244,6 @@ static void do_connect_step(const SSL_TEST_CTX *test_ctx, PEER *peer, |
| 158 | } | 158 | } |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | -typedef enum { | 161 | -typedef enum { |
| 162 | - /* Both parties succeeded. */ | 162 | - /* Both parties succeeded. */ |
| 163 | - HANDSHAKE_SUCCESS, | 163 | - HANDSHAKE_SUCCESS, |
| @@ -174,10 +174,10 @@ index e0422469e4..ae2ad59dd4 100644 | |||
| 174 | /* | 174 | /* |
| 175 | * Determine the handshake outcome. | 175 | * Determine the handshake outcome. |
| 176 | * last_status: the status of the peer to have acted last. | 176 | * last_status: the status of the peer to have acted last. |
| 177 | @@ -1539,6 +1602,10 @@ static HANDSHAKE_RESULT *do_handshake_internal( | 177 | @@ -1545,6 +1608,10 @@ static HANDSHAKE_RESULT *do_handshake_internal( |
| 178 | 178 | ||
| 179 | start = time(NULL); | 179 | start = time(NULL); |
| 180 | 180 | ||
| 181 | + save_loop_history(&(ret->history), | 181 | + save_loop_history(&(ret->history), |
| 182 | + phase, status, server.status, client.status, | 182 | + phase, status, server.status, client.status, |
| 183 | + client_turn_count, client_turn); | 183 | + client_turn_count, client_turn); |
| @@ -185,10 +185,10 @@ index e0422469e4..ae2ad59dd4 100644 | |||
| 185 | /* | 185 | /* |
| 186 | * Half-duplex handshake loop. | 186 | * Half-duplex handshake loop. |
| 187 | * Client and server speak to each other synchronously in the same process. | 187 | * Client and server speak to each other synchronously in the same process. |
| 188 | @@ -1560,6 +1627,10 @@ static HANDSHAKE_RESULT *do_handshake_internal( | 188 | @@ -1566,6 +1633,10 @@ static HANDSHAKE_RESULT *do_handshake_internal( |
| 189 | 0 /* server went last */); | 189 | 0 /* server went last */); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | + save_loop_history(&(ret->history), | 192 | + save_loop_history(&(ret->history), |
| 193 | + phase, status, server.status, client.status, | 193 | + phase, status, server.status, client.status, |
| 194 | + client_turn_count, client_turn); | 194 | + client_turn_count, client_turn); |
| @@ -208,9 +208,9 @@ index 78b03f9f4b..b9967c2623 100644 | |||
| 208 | * Licensed under the Apache License 2.0 (the "License"). You may not use | 208 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
| 209 | * this file except in compliance with the License. You can obtain a copy | 209 | * this file except in compliance with the License. You can obtain a copy |
| 210 | @@ -12,6 +12,11 @@ | 210 | @@ -12,6 +12,11 @@ |
| 211 | 211 | ||
| 212 | #include "ssl_test_ctx.h" | 212 | #include "ssl_test_ctx.h" |
| 213 | 213 | ||
| 214 | +#define MAX_HANDSHAKE_HISTORY_ENTRY_BIT 4 | 214 | +#define MAX_HANDSHAKE_HISTORY_ENTRY_BIT 4 |
| 215 | +#define MAX_HANDSHAKE_HISTORY_ENTRY (1 << MAX_HANDSHAKE_HISTORY_ENTRY_BIT) | 215 | +#define MAX_HANDSHAKE_HISTORY_ENTRY (1 << MAX_HANDSHAKE_HISTORY_ENTRY_BIT) |
| 216 | +#define MAX_HANDSHAKE_HISTORY_ENTRY_IDX_MASK \ | 216 | +#define MAX_HANDSHAKE_HISTORY_ENTRY_IDX_MASK \ |
| @@ -222,7 +222,7 @@ index 78b03f9f4b..b9967c2623 100644 | |||
| 222 | @@ -22,6 +27,63 @@ typedef struct ctx_data_st { | 222 | @@ -22,6 +27,63 @@ typedef struct ctx_data_st { |
| 223 | char *session_ticket_app_data; | 223 | char *session_ticket_app_data; |
| 224 | } CTX_DATA; | 224 | } CTX_DATA; |
| 225 | 225 | ||
| 226 | +typedef enum { | 226 | +typedef enum { |
| 227 | + HANDSHAKE, | 227 | + HANDSHAKE, |
| 228 | + RENEG_APPLICATION_DATA, | 228 | + RENEG_APPLICATION_DATA, |
| @@ -290,12 +290,12 @@ index 78b03f9f4b..b9967c2623 100644 | |||
| 290 | + /* handshake loop history */ | 290 | + /* handshake loop history */ |
| 291 | + HANDSHAKE_HISTORY history; | 291 | + HANDSHAKE_HISTORY history; |
| 292 | } HANDSHAKE_RESULT; | 292 | } HANDSHAKE_RESULT; |
| 293 | 293 | ||
| 294 | HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void); | 294 | HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void); |
| 295 | @@ -95,4 +159,8 @@ int configure_handshake_ctx_for_srp(SSL_CTX *server_ctx, SSL_CTX *server2_ctx, | 295 | @@ -95,4 +159,8 @@ int configure_handshake_ctx_for_srp(SSL_CTX *server_ctx, SSL_CTX *server2_ctx, |
| 296 | CTX_DATA *server2_ctx_data, | 296 | CTX_DATA *server2_ctx_data, |
| 297 | CTX_DATA *client_ctx_data); | 297 | CTX_DATA *client_ctx_data); |
| 298 | 298 | ||
| 299 | +const char *handshake_connect_phase_name(connect_phase_t phase); | 299 | +const char *handshake_connect_phase_name(connect_phase_t phase); |
| 300 | +const char *handshake_status_name(handshake_status_t handshake_status); | 300 | +const char *handshake_status_name(handshake_status_t handshake_status); |
| 301 | +const char *handshake_peer_status_name(peer_status_t peer_status); | 301 | +const char *handshake_peer_status_name(peer_status_t peer_status); |
| @@ -308,7 +308,7 @@ index ea608518f9..9d6b093c81 100644 | |||
| 308 | @@ -26,6 +26,44 @@ static OSSL_LIB_CTX *libctx = NULL; | 308 | @@ -26,6 +26,44 @@ static OSSL_LIB_CTX *libctx = NULL; |
| 309 | /* Currently the section names are of the form test-<number>, e.g. test-15. */ | 309 | /* Currently the section names are of the form test-<number>, e.g. test-15. */ |
| 310 | #define MAX_TESTCASE_NAME_LENGTH 100 | 310 | #define MAX_TESTCASE_NAME_LENGTH 100 |
| 311 | 311 | ||
| 312 | +static void print_handshake_history(const HANDSHAKE_HISTORY *history) | 312 | +static void print_handshake_history(const HANDSHAKE_HISTORY *history) |
| 313 | +{ | 313 | +{ |
| 314 | + size_t first_idx; | 314 | + size_t first_idx; |
diff --git a/meta/recipes-connectivity/openssl/openssl/0001-Configure-do-not-tweak-mips-cflags.patch b/meta/recipes-connectivity/openssl/openssl/0001-Configure-do-not-tweak-mips-cflags.patch index 502a7aaf32..3f6ab97795 100644 --- a/meta/recipes-connectivity/openssl/openssl/0001-Configure-do-not-tweak-mips-cflags.patch +++ b/meta/recipes-connectivity/openssl/openssl/0001-Configure-do-not-tweak-mips-cflags.patch | |||
| @@ -20,7 +20,7 @@ diff --git a/Configure b/Configure | |||
| 20 | index 4569952..adf019b 100755 | 20 | index 4569952..adf019b 100755 |
| 21 | --- a/Configure | 21 | --- a/Configure |
| 22 | +++ b/Configure | 22 | +++ b/Configure |
| 23 | @@ -1422,16 +1422,6 @@ if ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m) | 23 | @@ -1485,16 +1485,6 @@ if ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m) |
| 24 | push @{$config{shared_ldflag}}, "-mno-cygwin"; | 24 | push @{$config{shared_ldflag}}, "-mno-cygwin"; |
| 25 | } | 25 | } |
| 26 | 26 | ||
diff --git a/meta/recipes-connectivity/openssl/openssl/0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch b/meta/recipes-connectivity/openssl/openssl/0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch index bafdbaa46f..ce2acb2462 100644 --- a/meta/recipes-connectivity/openssl/openssl/0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch +++ b/meta/recipes-connectivity/openssl/openssl/0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch | |||
| @@ -38,7 +38,7 @@ Index: openssl-3.0.4/Configurations/unix-Makefile.tmpl | |||
| 38 | =================================================================== | 38 | =================================================================== |
| 39 | --- openssl-3.0.4.orig/Configurations/unix-Makefile.tmpl | 39 | --- openssl-3.0.4.orig/Configurations/unix-Makefile.tmpl |
| 40 | +++ openssl-3.0.4/Configurations/unix-Makefile.tmpl | 40 | +++ openssl-3.0.4/Configurations/unix-Makefile.tmpl |
| 41 | @@ -472,13 +472,23 @@ BIN_LDFLAGS={- join(' ', $target{bin_lfl | 41 | @@ -481,13 +481,23 @@ BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (), |
| 42 | '$(CNF_LDFLAGS)', '$(LDFLAGS)') -} | 42 | '$(CNF_LDFLAGS)', '$(LDFLAGS)') -} |
| 43 | BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS) | 43 | BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS) |
| 44 | 44 | ||
| @@ -67,7 +67,7 @@ Index: openssl-3.0.4/crypto/build.info | |||
| 67 | =================================================================== | 67 | =================================================================== |
| 68 | --- openssl-3.0.4.orig/crypto/build.info | 68 | --- openssl-3.0.4.orig/crypto/build.info |
| 69 | +++ openssl-3.0.4/crypto/build.info | 69 | +++ openssl-3.0.4/crypto/build.info |
| 70 | @@ -109,7 +109,7 @@ DEFINE[../libcrypto]=$UPLINKDEF | 70 | @@ -115,7 +115,7 @@ DEFINE[../libcrypto]=$UPLINKDEF |
| 71 | 71 | ||
| 72 | DEPEND[info.o]=buildinf.h | 72 | DEPEND[info.o]=buildinf.h |
| 73 | DEPEND[cversion.o]=buildinf.h | 73 | DEPEND[cversion.o]=buildinf.h |
diff --git a/meta/recipes-connectivity/openssl/openssl/CVE-2024-13176.patch b/meta/recipes-connectivity/openssl/openssl/CVE-2024-13176.patch deleted file mode 100644 index 28d4dd706a..0000000000 --- a/meta/recipes-connectivity/openssl/openssl/CVE-2024-13176.patch +++ /dev/null | |||
| @@ -1,126 +0,0 @@ | |||
| 1 | From 4b1cb94a734a7d4ec363ac0a215a25c181e11f65 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Tomas Mraz <tomas@openssl.org> | ||
| 3 | Date: Wed, 15 Jan 2025 18:27:02 +0100 | ||
| 4 | Subject: [PATCH] Fix timing side-channel in ECDSA signature computation | ||
| 5 | |||
| 6 | There is a timing signal of around 300 nanoseconds when the top word of | ||
| 7 | the inverted ECDSA nonce value is zero. This can happen with significant | ||
| 8 | probability only for some of the supported elliptic curves. In particular | ||
| 9 | the NIST P-521 curve is affected. To be able to measure this leak, the | ||
| 10 | attacker process must either be located in the same physical computer or | ||
| 11 | must have a very fast network connection with low latency. | ||
| 12 | |||
| 13 | Attacks on ECDSA nonce are also known as Minerva attack. | ||
| 14 | |||
| 15 | Fixes CVE-2024-13176 | ||
| 16 | |||
| 17 | Reviewed-by: Tim Hudson <tjh@openssl.org> | ||
| 18 | Reviewed-by: Neil Horman <nhorman@openssl.org> | ||
| 19 | Reviewed-by: Paul Dale <ppzgs1@gmail.com> | ||
| 20 | (Merged from https://github.com/openssl/openssl/pull/26429) | ||
| 21 | |||
| 22 | (cherry picked from commit 63c40a66c5dc287485705d06122d3a6e74a6a203) | ||
| 23 | (cherry picked from commit 392dcb336405a0c94486aa6655057f59fd3a0902) | ||
| 24 | |||
| 25 | CVE: CVE-2024-13176 | ||
| 26 | Upstream-Status: Backport [https://github.com/openssl/openssl/commit/4b1cb94a734a7d4ec363ac0a215a25c181e11f65] | ||
| 27 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
| 28 | --- | ||
| 29 | crypto/bn/bn_exp.c | 21 +++++++++++++++------ | ||
| 30 | crypto/ec/ec_lib.c | 7 ++++--- | ||
| 31 | include/crypto/bn.h | 3 +++ | ||
| 32 | 3 files changed, 22 insertions(+), 9 deletions(-) | ||
| 33 | |||
| 34 | diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c | ||
| 35 | index b876edbfac36e..af52e2ced6914 100644 | ||
| 36 | --- a/crypto/bn/bn_exp.c | ||
| 37 | +++ b/crypto/bn/bn_exp.c | ||
| 38 | @@ -606,7 +606,7 @@ static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top, | ||
| 39 | * out by Colin Percival, | ||
| 40 | * http://www.daemonology.net/hyperthreading-considered-harmful/) | ||
| 41 | */ | ||
| 42 | -int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 43 | +int bn_mod_exp_mont_fixed_top(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 44 | const BIGNUM *m, BN_CTX *ctx, | ||
| 45 | BN_MONT_CTX *in_mont) | ||
| 46 | { | ||
| 47 | @@ -623,10 +623,6 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 48 | unsigned int t4 = 0; | ||
| 49 | #endif | ||
| 50 | |||
| 51 | - bn_check_top(a); | ||
| 52 | - bn_check_top(p); | ||
| 53 | - bn_check_top(m); | ||
| 54 | - | ||
| 55 | if (!BN_is_odd(m)) { | ||
| 56 | ERR_raise(ERR_LIB_BN, BN_R_CALLED_WITH_EVEN_MODULUS); | ||
| 57 | return 0; | ||
| 58 | @@ -1146,7 +1142,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 59 | goto err; | ||
| 60 | } else | ||
| 61 | #endif | ||
| 62 | - if (!BN_from_montgomery(rr, &tmp, mont, ctx)) | ||
| 63 | + if (!bn_from_mont_fixed_top(rr, &tmp, mont, ctx)) | ||
| 64 | goto err; | ||
| 65 | ret = 1; | ||
| 66 | err: | ||
| 67 | @@ -1160,6 +1156,19 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 68 | return ret; | ||
| 69 | } | ||
| 70 | |||
| 71 | +int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 72 | + const BIGNUM *m, BN_CTX *ctx, | ||
| 73 | + BN_MONT_CTX *in_mont) | ||
| 74 | +{ | ||
| 75 | + bn_check_top(a); | ||
| 76 | + bn_check_top(p); | ||
| 77 | + bn_check_top(m); | ||
| 78 | + if (!bn_mod_exp_mont_fixed_top(rr, a, p, m, ctx, in_mont)) | ||
| 79 | + return 0; | ||
| 80 | + bn_correct_top(rr); | ||
| 81 | + return 1; | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, | ||
| 85 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 86 | { | ||
| 87 | diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c | ||
| 88 | index c92b4dcb0ac45..a79fbb98cf6fa 100644 | ||
| 89 | --- a/crypto/ec/ec_lib.c | ||
| 90 | +++ b/crypto/ec/ec_lib.c | ||
| 91 | @@ -21,6 +21,7 @@ | ||
| 92 | #include <openssl/opensslv.h> | ||
| 93 | #include <openssl/param_build.h> | ||
| 94 | #include "crypto/ec.h" | ||
| 95 | +#include "crypto/bn.h" | ||
| 96 | #include "internal/nelem.h" | ||
| 97 | #include "ec_local.h" | ||
| 98 | |||
| 99 | @@ -1261,10 +1262,10 @@ static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r, | ||
| 100 | if (!BN_sub(e, group->order, e)) | ||
| 101 | goto err; | ||
| 102 | /*- | ||
| 103 | - * Exponent e is public. | ||
| 104 | - * No need for scatter-gather or BN_FLG_CONSTTIME. | ||
| 105 | + * Although the exponent is public we want the result to be | ||
| 106 | + * fixed top. | ||
| 107 | */ | ||
| 108 | - if (!BN_mod_exp_mont(r, x, e, group->order, ctx, group->mont_data)) | ||
| 109 | + if (!bn_mod_exp_mont_fixed_top(r, x, e, group->order, ctx, group->mont_data)) | ||
| 110 | goto err; | ||
| 111 | |||
| 112 | ret = 1; | ||
| 113 | diff --git a/include/crypto/bn.h b/include/crypto/bn.h | ||
| 114 | index 302f031c2ff1d..499e1d10efab0 100644 | ||
| 115 | --- a/include/crypto/bn.h | ||
| 116 | +++ b/include/crypto/bn.h | ||
| 117 | @@ -73,6 +73,9 @@ int bn_set_words(BIGNUM *a, const BN_ULONG *words, int num_words); | ||
| 118 | */ | ||
| 119 | int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | ||
| 120 | BN_MONT_CTX *mont, BN_CTX *ctx); | ||
| 121 | +int bn_mod_exp_mont_fixed_top(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | ||
| 122 | + const BIGNUM *m, BN_CTX *ctx, | ||
| 123 | + BN_MONT_CTX *in_mont); | ||
| 124 | int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, | ||
| 125 | BN_CTX *ctx); | ||
| 126 | int bn_from_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, | ||
diff --git a/meta/recipes-connectivity/openssl/openssl/CVE-2024-9143.patch b/meta/recipes-connectivity/openssl/openssl/CVE-2024-9143.patch deleted file mode 100755 index 99c16cd573..0000000000 --- a/meta/recipes-connectivity/openssl/openssl/CVE-2024-9143.patch +++ /dev/null | |||
| @@ -1,202 +0,0 @@ | |||
| 1 | From bc7e04d7c8d509fb78fc0e285aa948fb0da04700 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Viktor Dukhovni <viktor@openssl.org> | ||
| 3 | Date: Thu, 19 Sep 2024 01:02:40 +1000 | ||
| 4 | Subject: [PATCH] Harden BN_GF2m_poly2arr against misuse. | ||
| 5 | |||
| 6 | The BN_GF2m_poly2arr() function converts characteristic-2 field | ||
| 7 | (GF_{2^m}) Galois polynomials from a representation as a BIGNUM bitmask, | ||
| 8 | to a compact array with just the exponents of the non-zero terms. | ||
| 9 | |||
| 10 | These polynomials are then used in BN_GF2m_mod_arr() to perform modular | ||
| 11 | reduction. A precondition of calling BN_GF2m_mod_arr() is that the | ||
| 12 | polynomial must have a non-zero constant term (i.e. the array has `0` as | ||
| 13 | its final element). | ||
| 14 | |||
| 15 | Internally, callers of BN_GF2m_poly2arr() did not verify that | ||
| 16 | precondition, and binary EC curve parameters with an invalid polynomial | ||
| 17 | could lead to out of bounds memory reads and writes in BN_GF2m_mod_arr(). | ||
| 18 | |||
| 19 | The precondition is always true for polynomials that arise from the | ||
| 20 | standard form of EC parameters for characteristic-two fields (X9.62). | ||
| 21 | See the "Finite Field Identification" section of: | ||
| 22 | |||
| 23 | https://www.itu.int/ITU-T/formal-language/itu-t/x/x894/2018-cor1/ANSI-X9-62.html | ||
| 24 | |||
| 25 | The OpenSSL GF(2^m) code supports only the trinomial and pentanomial | ||
| 26 | basis X9.62 forms. | ||
| 27 | |||
| 28 | This commit updates BN_GF2m_poly2arr() to return `0` (failure) when | ||
| 29 | the constant term is zero (i.e. the input bitmask BIGNUM is not odd). | ||
| 30 | |||
| 31 | Additionally, the return value is made unambiguous when there is not | ||
| 32 | enough space to also pad the array with a final `-1` sentinel value. | ||
| 33 | The return value is now always the number of elements (including the | ||
| 34 | final `-1`) that would be filled when the output array is sufficiently | ||
| 35 | large. Previously the same count was returned both when the array has | ||
| 36 | just enough room for the final `-1` and when it had only enough space | ||
| 37 | for non-sentinel values. | ||
| 38 | |||
| 39 | Finally, BN_GF2m_poly2arr() is updated to reject polynomials whose | ||
| 40 | degree exceeds `OPENSSL_ECC_MAX_FIELD_BITS`, this guards against | ||
| 41 | CPU exhausition attacks via excessively large inputs. | ||
| 42 | |||
| 43 | The above issues do not arise in processing X.509 certificates. These | ||
| 44 | generally have EC keys from "named curves", and RFC5840 (Section 2.1.1) | ||
| 45 | disallows explicit EC parameters. The TLS code in OpenSSL enforces this | ||
| 46 | constraint only after the certificate is decoded, but, even if explicit | ||
| 47 | parameters are specified, they are in X9.62 form, which cannot represent | ||
| 48 | problem values as noted above. | ||
| 49 | |||
| 50 | Initially reported as oss-fuzz issue 71623. | ||
| 51 | |||
| 52 | A closely related issue was earlier reported in | ||
| 53 | <https://github.com/openssl/openssl/issues/19826>. | ||
| 54 | |||
| 55 | Severity: Low, CVE-2024-9143 | ||
| 56 | |||
| 57 | Reviewed-by: Matt Caswell <matt@openssl.org> | ||
| 58 | Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> | ||
| 59 | Reviewed-by: Paul Dale <ppzgs1@gmail.com> | ||
| 60 | Reviewed-by: Tomas Mraz <tomas@openssl.org> | ||
| 61 | (Merged from https://github.com/openssl/openssl/pull/25639) | ||
| 62 | |||
| 63 | (cherry picked from commit 8e008cb8b23ec7dc75c45a66eeed09c815b11cd2) | ||
| 64 | |||
| 65 | CVE: CVE-2024-9143 | ||
| 66 | Upstream-Status: Backport [https://github.com/openssl/openssl/commit/bc7e04d7c8d509fb78fc0e285aa948fb0da04700] | ||
| 67 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
| 68 | --- | ||
| 69 | crypto/bn/bn_gf2m.c | 28 +++++++++++++++------- | ||
| 70 | test/ec_internal_test.c | 51 +++++++++++++++++++++++++++++++++++++++++ | ||
| 71 | 2 files changed, 71 insertions(+), 8 deletions(-) | ||
| 72 | |||
| 73 | diff --git a/crypto/bn/bn_gf2m.c b/crypto/bn/bn_gf2m.c | ||
| 74 | index 444c5ca7a3755..ae7e9d751c29c 100644 | ||
| 75 | --- a/crypto/bn/bn_gf2m.c | ||
| 76 | +++ b/crypto/bn/bn_gf2m.c | ||
| 77 | @@ -15,6 +15,7 @@ | ||
| 78 | #include "bn_local.h" | ||
| 79 | |||
| 80 | #ifndef OPENSSL_NO_EC2M | ||
| 81 | +# include <openssl/ec.h> | ||
| 82 | |||
| 83 | /* | ||
| 84 | * Maximum number of iterations before BN_GF2m_mod_solve_quad_arr should | ||
| 85 | @@ -1130,16 +1131,26 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 86 | /* | ||
| 87 | * Convert the bit-string representation of a polynomial ( \sum_{i=0}^n a_i * | ||
| 88 | * x^i) into an array of integers corresponding to the bits with non-zero | ||
| 89 | - * coefficient. Array is terminated with -1. Up to max elements of the array | ||
| 90 | - * will be filled. Return value is total number of array elements that would | ||
| 91 | - * be filled if array was large enough. | ||
| 92 | + * coefficient. The array is intended to be suitable for use with | ||
| 93 | + * `BN_GF2m_mod_arr()`, and so the constant term of the polynomial must not be | ||
| 94 | + * zero. This translates to a requirement that the input BIGNUM `a` is odd. | ||
| 95 | + * | ||
| 96 | + * Given sufficient room, the array is terminated with -1. Up to max elements | ||
| 97 | + * of the array will be filled. | ||
| 98 | + * | ||
| 99 | + * The return value is total number of array elements that would be filled if | ||
| 100 | + * array was large enough, including the terminating `-1`. It is `0` when `a` | ||
| 101 | + * is not odd or the constant term is zero contrary to requirement. | ||
| 102 | + * | ||
| 103 | + * The return value is also `0` when the leading exponent exceeds | ||
| 104 | + * `OPENSSL_ECC_MAX_FIELD_BITS`, this guards against CPU exhaustion attacks, | ||
| 105 | */ | ||
| 106 | int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max) | ||
| 107 | { | ||
| 108 | int i, j, k = 0; | ||
| 109 | BN_ULONG mask; | ||
| 110 | |||
| 111 | - if (BN_is_zero(a)) | ||
| 112 | + if (!BN_is_odd(a)) | ||
| 113 | return 0; | ||
| 114 | |||
| 115 | for (i = a->top - 1; i >= 0; i--) { | ||
| 116 | @@ -1157,12 +1168,13 @@ int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max) | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | - if (k < max) { | ||
| 121 | + if (k > 0 && p[0] > OPENSSL_ECC_MAX_FIELD_BITS) | ||
| 122 | + return 0; | ||
| 123 | + | ||
| 124 | + if (k < max) | ||
| 125 | p[k] = -1; | ||
| 126 | - k++; | ||
| 127 | - } | ||
| 128 | |||
| 129 | - return k; | ||
| 130 | + return k + 1; | ||
| 131 | } | ||
| 132 | |||
| 133 | /* | ||
| 134 | diff --git a/test/ec_internal_test.c b/test/ec_internal_test.c | ||
| 135 | index 5076f9894d5b8..92904cfc42b20 100644 | ||
| 136 | --- a/test/ec_internal_test.c | ||
| 137 | +++ b/test/ec_internal_test.c | ||
| 138 | @@ -155,6 +155,56 @@ static int field_tests_ecp_mont(void) | ||
| 139 | } | ||
| 140 | |||
| 141 | #ifndef OPENSSL_NO_EC2M | ||
| 142 | +/* Test that decoding of invalid GF2m field parameters fails. */ | ||
| 143 | +static int ec2m_field_sanity(void) | ||
| 144 | +{ | ||
| 145 | + int ret = 0; | ||
| 146 | + BN_CTX *ctx = BN_CTX_new(); | ||
| 147 | + BIGNUM *p, *a, *b; | ||
| 148 | + EC_GROUP *group1 = NULL, *group2 = NULL, *group3 = NULL; | ||
| 149 | + | ||
| 150 | + TEST_info("Testing GF2m hardening\n"); | ||
| 151 | + | ||
| 152 | + BN_CTX_start(ctx); | ||
| 153 | + p = BN_CTX_get(ctx); | ||
| 154 | + a = BN_CTX_get(ctx); | ||
| 155 | + if (!TEST_ptr(b = BN_CTX_get(ctx)) | ||
| 156 | + || !TEST_true(BN_one(a)) | ||
| 157 | + || !TEST_true(BN_one(b))) | ||
| 158 | + goto out; | ||
| 159 | + | ||
| 160 | + /* Even pentanomial value should be rejected */ | ||
| 161 | + if (!TEST_true(BN_set_word(p, 0xf2))) | ||
| 162 | + goto out; | ||
| 163 | + if (!TEST_ptr_null(group1 = EC_GROUP_new_curve_GF2m(p, a, b, ctx))) | ||
| 164 | + TEST_error("Zero constant term accepted in GF2m polynomial"); | ||
| 165 | + | ||
| 166 | + /* Odd hexanomial should also be rejected */ | ||
| 167 | + if (!TEST_true(BN_set_word(p, 0xf3))) | ||
| 168 | + goto out; | ||
| 169 | + if (!TEST_ptr_null(group2 = EC_GROUP_new_curve_GF2m(p, a, b, ctx))) | ||
| 170 | + TEST_error("Hexanomial accepted as GF2m polynomial"); | ||
| 171 | + | ||
| 172 | + /* Excessive polynomial degree should also be rejected */ | ||
| 173 | + if (!TEST_true(BN_set_word(p, 0x71)) | ||
| 174 | + || !TEST_true(BN_set_bit(p, OPENSSL_ECC_MAX_FIELD_BITS + 1))) | ||
| 175 | + goto out; | ||
| 176 | + if (!TEST_ptr_null(group3 = EC_GROUP_new_curve_GF2m(p, a, b, ctx))) | ||
| 177 | + TEST_error("GF2m polynomial degree > %d accepted", | ||
| 178 | + OPENSSL_ECC_MAX_FIELD_BITS); | ||
| 179 | + | ||
| 180 | + ret = group1 == NULL && group2 == NULL && group3 == NULL; | ||
| 181 | + | ||
| 182 | + out: | ||
| 183 | + EC_GROUP_free(group1); | ||
| 184 | + EC_GROUP_free(group2); | ||
| 185 | + EC_GROUP_free(group3); | ||
| 186 | + BN_CTX_end(ctx); | ||
| 187 | + BN_CTX_free(ctx); | ||
| 188 | + | ||
| 189 | + return ret; | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | /* test EC_GF2m_simple_method directly */ | ||
| 193 | static int field_tests_ec2_simple(void) | ||
| 194 | { | ||
| 195 | @@ -443,6 +493,7 @@ int setup_tests(void) | ||
| 196 | ADD_TEST(field_tests_ecp_simple); | ||
| 197 | ADD_TEST(field_tests_ecp_mont); | ||
| 198 | #ifndef OPENSSL_NO_EC2M | ||
| 199 | + ADD_TEST(ec2m_field_sanity); | ||
| 200 | ADD_TEST(field_tests_ec2_simple); | ||
| 201 | #endif | ||
| 202 | ADD_ALL_TESTS(field_tests_default, crv_len); | ||
diff --git a/meta/recipes-connectivity/openssl/openssl_3.2.3.bb b/meta/recipes-connectivity/openssl/openssl_3.2.4.bb index 0b47bab550..bada192fe9 100644 --- a/meta/recipes-connectivity/openssl/openssl_3.2.3.bb +++ b/meta/recipes-connectivity/openssl/openssl_3.2.4.bb | |||
| @@ -12,15 +12,13 @@ SRC_URI = "https://github.com/openssl/openssl/releases/download/openssl-${PV}/op | |||
| 12 | file://0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch \ | 12 | file://0001-buildinfo-strip-sysroot-and-debug-prefix-map-from-co.patch \ |
| 13 | file://0001-Configure-do-not-tweak-mips-cflags.patch \ | 13 | file://0001-Configure-do-not-tweak-mips-cflags.patch \ |
| 14 | file://0001-Added-handshake-history-reporting-when-test-fails.patch \ | 14 | file://0001-Added-handshake-history-reporting-when-test-fails.patch \ |
| 15 | file://CVE-2024-9143.patch \ | ||
| 16 | file://CVE-2024-13176.patch \ | ||
| 17 | " | 15 | " |
| 18 | 16 | ||
| 19 | SRC_URI:append:class-nativesdk = " \ | 17 | SRC_URI:append:class-nativesdk = " \ |
| 20 | file://environment.d-openssl.sh \ | 18 | file://environment.d-openssl.sh \ |
| 21 | " | 19 | " |
| 22 | 20 | ||
| 23 | SRC_URI[sha256sum] = "52b5f1c6b8022bc5868c308c54fb77705e702d6c6f4594f99a0df216acf46239" | 21 | SRC_URI[sha256sum] = "b23ad7fd9f73e43ad1767e636040e88ba7c9e5775bfa5618436a0dd2c17c3716" |
| 24 | 22 | ||
| 25 | inherit lib_package multilib_header multilib_script ptest perlnative manpages | 23 | inherit lib_package multilib_header multilib_script ptest perlnative manpages |
| 26 | MULTILIB_SCRIPTS = "${PN}-bin:${bindir}/c_rehash" | 24 | MULTILIB_SCRIPTS = "${PN}-bin:${bindir}/c_rehash" |
