openssl/crypto
Viktor Dukhovni c0d3e4d32d Harden BN_GF2m_poly2arr against misuse.
The BN_GF2m_poly2arr() function converts characteristic-2 field
(GF_{2^m}) Galois polynomials from a representation as a BIGNUM bitmask,
to a compact array with just the exponents of the non-zero terms.

These polynomials are then used in BN_GF2m_mod_arr() to perform modular
reduction.  A precondition of calling BN_GF2m_mod_arr() is that the
polynomial must have a non-zero constant term (i.e. the array has `0` as
its final element).

Internally, callers of BN_GF2m_poly2arr() did not verify that
precondition, and binary EC curve parameters with an invalid polynomial
could lead to out of bounds memory reads and writes in BN_GF2m_mod_arr().

The precondition is always true for polynomials that arise from the
standard form of EC parameters for characteristic-two fields (X9.62).
See the "Finite Field Identification" section of:

    https://www.itu.int/ITU-T/formal-language/itu-t/x/x894/2018-cor1/ANSI-X9-62.html

The OpenSSL GF(2^m) code supports only the trinomial and pentanomial
basis X9.62 forms.

This commit updates BN_GF2m_poly2arr() to return `0` (failure) when
the constant term is zero (i.e. the input bitmask BIGNUM is not odd).

Additionally, the return value is made unambiguous when there is not
enough space to also pad the array with a final `-1` sentinel value.
The return value is now always the number of elements (including the
final `-1`) that would be filled when the output array is sufficiently
large.  Previously the same count was returned both when the array has
just enough room for the final `-1` and when it had only enough space
for non-sentinel values.

Finally, BN_GF2m_poly2arr() is updated to reject polynomials whose
degree exceeds `OPENSSL_ECC_MAX_FIELD_BITS`, this guards against
CPU exhausition attacks via excessively large inputs.

The above issues do not arise in processing X.509 certificates.  These
generally have EC keys from "named curves", and RFC5840 (Section 2.1.1)
disallows explicit EC parameters.  The TLS code in OpenSSL enforces this
constraint only after the certificate is decoded, but, even if explicit
parameters are specified, they are in X9.62 form, which cannot represent
problem values as noted above.

Initially reported as oss-fuzz issue 71623.

A closely related issue was earlier reported in
<https://github.com/openssl/openssl/issues/19826>.

Severity: Low, CVE-2024-9143

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25639)

(cherry picked from commit 8e008cb8b2)
2024-10-16 09:22:09 +02:00
..
aes enable AES-XTS optimization for AIX 2024-06-05 10:14:25 +02:00
aria
asn1 Copyright year updates 2024-09-03 14:44:27 +02:00
async Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
bf Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
bio replace various calls to sprintf() by BiO_snprintf() to avoid compiler warnings, e.g., on MacOS 2024-10-12 15:42:53 +02:00
bn Harden BN_GF2m_poly2arr against misuse. 2024-10-16 09:22:09 +02:00
buffer Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
camellia
cast Copyright year updates 2023-09-07 09:59:15 +01:00
chacha Fix big-endian Power10 chacha20 implementation 2024-09-19 11:13:59 +02:00
cmac Copyright year updates 2024-03-20 13:07:54 +01:00
cmp Fix potential memory leak in save_statusInfo() 2024-10-07 17:58:41 +02:00
cms Fix memleak in rsa_cms_sign error path 2024-09-05 17:05:17 +02:00
comp Copyright year updates 2023-09-07 09:59:15 +01:00
conf Copyright year updates 2024-09-03 14:44:27 +02:00
crmf Copyright year updates 2023-09-07 09:59:15 +01:00
ct Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
des Copyright year updates 2023-09-07 09:59:15 +01:00
dh Copyright year updates 2024-03-20 13:07:54 +01:00
dsa Copyright year updates 2024-06-04 14:50:58 +02:00
dso replace various calls to sprintf() by BiO_snprintf() to avoid compiler warnings, e.g., on MacOS 2024-10-12 15:42:53 +02:00
ec Remove double engine reference in ossl_ec_key_dup() 2024-09-26 10:27:04 +02:00
encode_decode Copyright year updates 2024-03-20 13:07:54 +01:00
engine Copyright year updates 2024-09-03 14:44:27 +02:00
err Add reason codes with the correct offset for two alerts 2024-05-14 15:27:42 +02:00
ess Copyright year updates 2024-06-04 14:50:58 +02:00
evp Copyright year updates 2024-09-03 14:44:27 +02:00
ffc DH_check_pub_key() should not fail when setting result code 2023-10-11 16:22:27 +02:00
hmac
hpke Copyright year updates 2024-03-20 13:07:54 +01:00
http OSSL_HTTP_adapt_proxy(): fix handling of escaped IPv6 host addresses and of whitespace in no_proxy 2024-09-23 22:16:54 +02:00
idea Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
kdf
lhash Copyright year updates 2024-03-20 13:07:54 +01:00
md2 Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
md4 Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
md5 md5: add assembly implementation for loongarch64 2023-12-27 10:15:29 +01:00
mdc2 Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
modes fix small footprint builds on arm 2024-09-12 09:10:49 +10:00
objects Fix error handling in OBJ_add_object 2024-08-21 15:53:57 +02:00
ocsp Copyright year updates 2023-09-07 09:59:15 +01:00
pem Fix Edge Cases in Password Callback Handling 2024-09-09 09:01:06 +02:00
perlasm Copyright year updates 2024-06-04 14:50:58 +02:00
pkcs7 Fix potential memory leak in PKCS7_signatureVerify() 2024-10-07 17:56:12 +02:00
pkcs12 Copyright year updates 2024-09-03 14:44:27 +02:00
poly1305 Copyright year updates 2024-03-20 13:07:54 +01:00
property Copyright year updates 2024-09-03 14:44:27 +02:00
rand Copyright year updates 2024-09-03 14:44:27 +02:00
rc2 Copyright year updates 2023-09-07 09:59:15 +01:00
rc4 Copyright year updates 2023-09-07 09:59:15 +01:00
rc5 Copyright year updates 2023-09-07 09:59:15 +01:00
ripemd Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
rsa Copyright year updates 2024-09-03 14:44:27 +02:00
seed Avoid duplicating symbols in legacy.a with some build options 2023-01-31 11:10:22 +11:00
sha Fix a few incorrect paths in some build.info files 2024-02-02 14:12:49 +01:00
siphash crypto/*: Fix various typos, repeated words, align some spelling to LDP. 2022-10-12 16:55:01 +11:00
sm2 fix sm2 encryption implementation bug. 2024-05-15 11:17:42 +02:00
sm3 Copyright year updates 2024-09-03 14:44:27 +02:00
sm4 Copyright year updates 2024-03-20 13:07:54 +01:00
srp Fix potential double free through SRP_user_pwd_set1_ids() 2024-10-11 14:23:09 +02:00
stack Copyright year updates 2024-03-20 13:07:54 +01:00
store Copyright year updates 2024-06-04 14:50:58 +02:00
thread Fix no-thread-pool build on Windows 2024-09-10 16:37:27 +02:00
ts Copyright year updates 2023-09-07 09:59:15 +01:00
txt_db Copyright year updates 2023-09-07 09:59:15 +01:00
ui Fix Edge Cases in Password Callback Handling 2024-09-09 09:01:06 +02:00
whrlpool Copyright year updates 2023-09-07 09:59:15 +01:00
x509 Increase limit for CRL download 2024-10-08 16:00:10 +02:00
LPdir_nyi.c
LPdir_unix.c Copyright year updates 2023-09-07 09:59:15 +01:00
LPdir_vms.c
LPdir_win.c
LPdir_win32.c
LPdir_wince.c
README-sparse_array.md
alphacpuid.pl
arm64cpuid.pl
arm_arch.h Copyright year updates 2024-03-20 13:07:54 +01:00
armcap.c Copyright year updates 2024-03-20 13:07:54 +01:00
armv4cpuid.pl Copyright year updates 2023-09-07 09:59:15 +01:00
asn1_dsa.c
bsearch.c
build.info Do not include sparse_array.o in libssl 2023-09-22 20:42:48 +02:00
c64xpluscpuid.pl
context.c docs: document that *_free(NULL) does nothing 2024-06-27 18:27:20 +02:00
core_algorithm.c Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
core_fetch.c
core_namemap.c Copyright year updates 2023-09-07 09:59:15 +01:00
cpt_err.c
cpuid.c Copyright year updates 2023-09-28 14:23:29 +01:00
cryptlib.c Copyright year updates 2023-09-07 09:59:15 +01:00
ctype.c Copyright year updates 2023-09-07 09:59:15 +01:00
cversion.c
der_writer.c
deterministic_nonce.c Copyright year updates 2024-06-04 14:50:58 +02:00
dllmain.c
ebcdic.c
ex_data.c Fix error handling in CRYPTO_get_ex_new_index 2023-09-21 14:43:08 +02:00
getenv.c
ia64cpuid.S
info.c Copyright year updates 2023-09-07 09:59:15 +01:00
init.c Copyright year updates 2024-03-20 13:07:54 +01:00
initthread.c Recycle the TLS key that holds thread_event_handler 2024-09-05 17:20:19 +02:00
loongarch64cpuid.pl LoongArch64 assembly pack: Really implement OPENSSL_rdtsc 2023-12-19 18:34:34 +01:00
loongarch_arch.h Copyright year updates 2023-09-07 09:59:15 +01:00
loongarchcap.c Copyright year updates 2023-09-07 09:59:15 +01:00
mem.c Windows: use srand() instead of srandom() 2023-10-13 15:04:42 +02:00
mem_clr.c
mem_sec.c Add locking to CRYPTO_secure_used 2023-12-01 09:03:04 -05:00
mips_arch.h
o_dir.c
o_fopen.c crypto: Fix various typos, repeated words, align some spelling to LDP. 2022-10-12 16:55:01 +11:00
o_init.c
o_str.c OPENSSL_hexstr2buf_ex(): Handle zero-length input correctly 2024-07-02 20:14:19 +02:00
o_time.c
packet.c Copyright year updates 2023-09-07 09:59:15 +01:00
param_build.c params: drop INT_MAX checks 2023-12-29 10:21:10 +01:00
param_build_set.c ossl_param_build_set_multi_key_bn(): Do not set NULL BIGNUMs 2023-10-18 18:07:13 +02:00
params.c uefi: move variables 2024-05-30 18:38:39 +02:00
params_dup.c Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
params_from_text.c Copyright year updates 2024-03-20 13:07:54 +01:00
params_idx.c.in params: provide a faster TRIE based param lookup. 2023-06-02 15:13:20 +10:00
pariscid.pl
passphrase.c Stop raising ERR_R_MALLOC_FAILURE in most places 2022-10-05 14:02:03 +02:00
ppccap.c
ppccpuid.pl
provider.c Copyright year updates 2023-09-07 09:59:15 +01:00
provider_child.c Copyright year updates 2023-09-07 09:59:15 +01:00
provider_conf.c Fix remaining provider config settings to be decisive in value 2023-12-27 09:32:48 +01:00
provider_core.c Fix up path generation to use OPENSSL_MODULES 2024-04-18 18:39:49 +02:00
provider_local.h
provider_predefined.c
punycode.c Copyright year updates 2023-09-07 09:59:15 +01:00
quic_vlint.c QUIC: Enable building with QUIC support disabled 2023-01-13 13:20:16 +00:00
rcu_internal.h Copyright year updates 2024-03-20 13:07:54 +01:00
riscv32cpuid.pl Copyright year updates 2024-06-04 14:50:58 +02:00
riscv64cpuid.pl riscv: Add basic vector extension support 2023-10-26 15:55:49 +01:00
riscvcap.c Avoid undefined behaviour with the <ctype.h> functions. 2024-10-10 20:48:21 +02:00
s390x_arch.h Copyright year updates 2023-09-07 09:59:15 +01:00
s390xcap.c Copyright year updates 2023-09-07 09:59:15 +01:00
s390xcpuid.pl
self_test_core.c
sleep.c NonStop: Do not call sleep() with a 0 value 2024-04-05 16:06:51 +02:00
sparccpuid.S
sparcv9cap.c
sparse_array.c
threads_lib.c Define threads_lib.c functions only for OPENSSL_SYS_UNIX 2022-11-14 07:47:53 +00:00
threads_none.c Some minor nit corrections in the thread code for rcu 2024-06-20 16:54:40 +02:00
threads_pthread.c Some minor nit corrections in the thread code for rcu 2024-06-20 16:54:40 +02:00
threads_win.c threads_win: fix improper cast to long * instead of LONG * 2024-09-05 17:11:37 +02:00
time.c Copyright year updates 2023-09-07 09:59:15 +01:00
trace.c "foo * bar" should be "foo *bar" 2023-09-11 10:15:30 +02:00
uid.c Copyright year updates 2023-09-07 09:59:15 +01:00
vms_rms.h
x86_64cpuid.pl
x86cpuid.pl