Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/8.4-stable' into 8.4-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
InfoHunter committed Dec 14, 2023
2 parents 60ae61b + 6a2e56e commit a59b923
Show file tree
Hide file tree
Showing 26 changed files with 719 additions and 125 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ jobs:
- name: check dirty
run: test $(git status --porcelain | wc -l) -eq "0"

zkp-test:
ntls:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: config
run: CC=clang ./config --strict-warnings --debug -O1 -fsanitize=memory -DOSSL_SANITIZE_MEMORY enable-ec_elgamal enable-twisted_ec_elgamal enable-bulletproofs enable-nizk enable-zkp-gadget && perl configdata.pm --dump
run: CC=clang ./config --strict-warnings --debug -O1 -fsanitize=memory -DOSSL_SANITIZE_MEMORY && perl configdata.pm --dump
- name: make
run: make -s -j4
- name: make test
Expand All @@ -378,3 +378,16 @@ jobs:
- name: check dirty
run: test $(git status --porcelain | wc -l) -eq "0"

zkp-build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: config
run: CC=clang ./config --strict-warnings --debug -O1 -fsanitize=memory -DOSSL_SANITIZE_MEMORY enable-ec_elgamal enable-twisted_ec_elgamal enable-bulletproofs enable-nizk enable-zkp-gadget && perl configdata.pm --dump
- name: make
run: make -s -j4
- name: make clean
run: make clean
- name: check dirty
run: test $(git status --porcelain | wc -l) -eq "0"

4 changes: 4 additions & 0 deletions .github/workflows/run-checker-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ jobs:
no-zlib,
enable-zlib-dynamic,
no-zlib-dynamic,
enable-ntls,
enable-ec_elgamal enable-twisted_ec_elgamal,
enable-bulletproofs,
enable-bulletproofs enable-nizk enable-zkp-gadget enable-ec_elgamal enable-twisted_ec_elgamal,
-DOPENSSL_NO_BUILTIN_OVERFLOW_CHECKING
]
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

Changes between 8.4.0-pre3 and 8.4.0-pre4 [xx XXX xxxx]

*)
*) 修复CVE-2023-4807

*) 修复CVE-2023-5363

*) 修复CVE-2023-5678

Changes between 8.4.0-pre2 and 8.4.0-pre3 [08 Oct 2023]

Expand Down
12 changes: 12 additions & 0 deletions crypto/dh/dh_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key)
*/
int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
{
/* Don't do any checks at all with an excessively large modulus */
if (BN_num_bits(dh->params.p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) {
ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_LARGE);
*ret = DH_MODULUS_TOO_LARGE | DH_CHECK_PUBKEY_INVALID;
return 0;
}

if (dh->params.q != NULL && BN_ucmp(dh->params.p, dh->params.q) < 0) {
*ret |= DH_CHECK_INVALID_Q_VALUE | DH_CHECK_PUBKEY_INVALID;
return 1;
}

return ossl_ffc_validate_public_key(&dh->params, pub_key, ret);
}

Expand Down
3 changes: 2 additions & 1 deletion crypto/dh/dh_err.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -54,6 +54,7 @@ static const ERR_STRING_DATA DH_str_reasons[] = {
{ERR_PACK(ERR_LIB_DH, 0, DH_R_PARAMETER_ENCODING_ERROR),
"parameter encoding error"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_PEER_KEY_ERROR), "peer key error"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_Q_TOO_LARGE), "q too large"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_SHARED_INFO_ERROR), "shared info error"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_UNABLE_TO_CHECK_GENERATOR),
"unable to check generator"},
Expand Down
12 changes: 12 additions & 0 deletions crypto/dh/dh_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ int ossl_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
goto err;
}

if (dh->params.q != NULL
&& BN_num_bits(dh->params.q) > OPENSSL_DH_MAX_MODULUS_BITS) {
ERR_raise(ERR_LIB_DH, DH_R_Q_TOO_LARGE);
goto err;
}

if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) {
ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL);
return 0;
Expand Down Expand Up @@ -268,6 +274,12 @@ static int generate_key(DH *dh)
return 0;
}

if (dh->params.q != NULL
&& BN_num_bits(dh->params.q) > OPENSSL_DH_MAX_MODULUS_BITS) {
ERR_raise(ERR_LIB_DH, DH_R_Q_TOO_LARGE);
return 0;
}

if (BN_num_bits(dh->params.p) < DH_MIN_MODULUS_BITS) {
ERR_raise(ERR_LIB_DH, DH_R_MODULUS_TOO_SMALL);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion crypto/ec/ecx_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ const EVP_PKEY_ASN1_METHOD ossl_ed448_asn1_meth = {
static int pkey_ecx_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
ECX_KEY *ecx = ossl_ecx_key_op(NULL, NULL, 0, ctx->pmeth->pkey_id,
KEY_OP_PUBLIC, NULL, NULL);
KEY_OP_KEYGEN, NULL, NULL);

if (ecx != NULL) {
EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, ecx);
Expand Down
1 change: 1 addition & 0 deletions crypto/err/openssl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ DH_R_NO_PARAMETERS_SET:107:no parameters set
DH_R_NO_PRIVATE_VALUE:100:no private value
DH_R_PARAMETER_ENCODING_ERROR:105:parameter encoding error
DH_R_PEER_KEY_ERROR:111:peer key error
DH_R_Q_TOO_LARGE:130:q too large
DH_R_SHARED_INFO_ERROR:113:shared info error
DH_R_UNABLE_TO_CHECK_GENERATOR:121:unable to check generator
DSA_R_BAD_FFC_PARAMETERS:114:bad ffc parameters
Expand Down
36 changes: 36 additions & 0 deletions crypto/evp/evp_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,42 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx,
return 0;
}

#ifndef FIPS_MODULE
/*
* Fix for CVE-2023-5363
* Passing in a size as part of the init call takes effect late
* so, force such to occur before the initialisation.
*
* The FIPS provider's internal library context is used in a manner
* such that this is not an issue.
*/
if (params != NULL) {
OSSL_PARAM param_lens[3] = { OSSL_PARAM_END, OSSL_PARAM_END,
OSSL_PARAM_END };
OSSL_PARAM *q = param_lens;
const OSSL_PARAM *p;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
if (p != NULL)
memcpy(q++, p, sizeof(*q));

/*
* Note that OSSL_CIPHER_PARAM_AEAD_IVLEN is a synomym for
* OSSL_CIPHER_PARAM_IVLEN so both are covered here.
*/
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_IVLEN);
if (p != NULL)
memcpy(q++, p, sizeof(*q));

if (q != param_lens) {
if (!EVP_CIPHER_CTX_set_params(ctx, param_lens)) {
ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_LENGTH);
return 0;
}
}
}
#endif

if (enc) {
if (ctx->cipher->einit == NULL) {
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
Expand Down
6 changes: 3 additions & 3 deletions crypto/poly1305/asm/poly1305-x86_64.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env perl
# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
# Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -195,7 +195,7 @@ sub poly1305_iteration {
bt \$`5+32`,%r9 # AVX2?
cmovc %rax,%r10
___
$code.=<<___ if ($avx>3);
$code.=<<___ if ($avx>3 && !$win64);
mov \$`(1<<31|1<<21|1<<16)`,%rax
shr \$32,%r9
and %rax,%r9
Expand Down Expand Up @@ -2724,7 +2724,7 @@ sub poly1305_iteration {
.cfi_endproc
.size poly1305_blocks_avx512,.-poly1305_blocks_avx512
___
if ($avx>3) {
if ($avx>3 && !$win64) {
########################################################################
# VPMADD52 version using 2^44 radix.
#
Expand Down
2 changes: 1 addition & 1 deletion include/crypto/dherr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down
9 changes: 7 additions & 2 deletions include/internal/ffc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@
# define FFC_CHECK_INVALID_Q_VALUE 0x00020
# define FFC_CHECK_INVALID_J_VALUE 0x00040

# define FFC_CHECK_BAD_LN_PAIR 0x00080
# define FFC_CHECK_INVALID_SEED_SIZE 0x00100
/*
* 0x80, 0x100 reserved by include/openssl/dh.h with check bits that are not
* relevant for FFC.
*/

# define FFC_CHECK_MISSING_SEED_OR_COUNTER 0x00200
# define FFC_CHECK_INVALID_G 0x00400
# define FFC_CHECK_INVALID_PQ 0x00800
Expand All @@ -68,6 +71,8 @@
# define FFC_CHECK_Q_MISMATCH 0x04000
# define FFC_CHECK_G_MISMATCH 0x08000
# define FFC_CHECK_COUNTER_MISMATCH 0x10000
# define FFC_CHECK_BAD_LN_PAIR 0x20000
# define FFC_CHECK_INVALID_SEED_SIZE 0x40000

/* Validation Return codes */
# define FFC_ERROR_PUBKEY_TOO_SMALL 0x01
Expand Down
6 changes: 3 additions & 3 deletions include/openssl/dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ DECLARE_ASN1_ITEM(DHparams)
# define DH_GENERATOR_3 3
# define DH_GENERATOR_5 5

/* DH_check error codes */
/* DH_check error codes, some of them shared with DH_check_pub_key */
/*
* NB: These values must align with the equivalently named macros in
* internal/ffc.h.
Expand All @@ -151,10 +151,10 @@ DECLARE_ASN1_ITEM(DHparams)
# define DH_UNABLE_TO_CHECK_GENERATOR 0x04
# define DH_NOT_SUITABLE_GENERATOR 0x08
# define DH_CHECK_Q_NOT_PRIME 0x10
# define DH_CHECK_INVALID_Q_VALUE 0x20
# define DH_CHECK_INVALID_Q_VALUE 0x20 /* +DH_check_pub_key */
# define DH_CHECK_INVALID_J_VALUE 0x40
# define DH_MODULUS_TOO_SMALL 0x80
# define DH_MODULUS_TOO_LARGE 0x100
# define DH_MODULUS_TOO_LARGE 0x100 /* +DH_check_pub_key */

/* DH_check_pub_key error codes */
# define DH_CHECK_PUBKEY_TOO_SMALL 0x01
Expand Down
3 changes: 2 additions & 1 deletion include/openssl/dherr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -50,6 +50,7 @@
# define DH_R_NO_PRIVATE_VALUE 100
# define DH_R_PARAMETER_ENCODING_ERROR 105
# define DH_R_PEER_KEY_ERROR 111
# define DH_R_Q_TOO_LARGE 130
# define DH_R_SHARED_INFO_ERROR 113
# define DH_R_UNABLE_TO_CHECK_GENERATOR 121

Expand Down
35 changes: 35 additions & 0 deletions ssl/ssl_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,38 @@ static int cmd_Enable_sign_by_dc(SSL_CONF_CTX *cctx, const char *value)
}
#endif

#ifndef OPENSSL_NO_SSL_TRACE
static void trace_cb(int write_p, int version, int content_type,
const void *buf, size_t msglen, SSL *ssl, void *arg)
{
BIO *bio = NULL;
if (arg == NULL) {
bio = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
if (bio == NULL)
return;

arg = bio;
}

SSL_trace(write_p, version, content_type, buf, msglen, ssl, arg);

BIO_free(bio);
}

static int cmd_Trace(SSL_CONF_CTX *cctx, const char *value)
{
if (strcmp(value, "on") == 0) {
if (cctx->ctx)
SSL_CTX_set_msg_callback(cctx->ctx, trace_cb);

if (cctx->ssl)
SSL_set_msg_callback(cctx->ssl, trace_cb);
}

return 1;
}
#endif

typedef struct {
int (*cmd) (SSL_CONF_CTX *cctx, const char *value);
const char *str_file;
Expand Down Expand Up @@ -986,6 +1018,9 @@ static const ssl_conf_cmd_tbl ssl_conf_cmds[] = {
SSL_CONF_CMD_STRING(Enable_verify_peer_by_dc, "Enable_verify_peer_by_dc", 0),
SSL_CONF_CMD_STRING(Enable_sign_by_dc, "Enable_sign_by_dc", 0),
#endif
#ifndef OPENSSL_NO_SSL_TRACE
SSL_CONF_CMD_STRING(Trace, "Trace", 0),
#endif
};

/* Supported switches: must match order of switches in ssl_conf_cmds */
Expand Down
50 changes: 50 additions & 0 deletions ssl/statem/extensions_clnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,56 @@ EXT_RETURN tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt,
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return EXT_RETURN_FAIL;
}

#ifndef OPENSSL_NO_SM2
/*
* RFC 8998 requires that:
* For the key_share extension, a KeyShareEntry for the "curveSM2" group
* MUST be included. We re-order curveSM2 to the first supported group when
* enable_sm_tls13_strict so that the key_share extension will include a
* KeyShareEntry for the "curveSM2" group because only one KeyShareEntry is
* sent now.
*/
if (!SSL_IS_DTLS(s) && max_version >= TLS1_3_VERSION
&& s->enable_sm_tls13_strict == 1) {
int sm2_idx = -1;

for (i = 0; i < num_groups; i++) {
if (pgroups[i] == TLSEXT_curve_SM2) {
sm2_idx = i;
break;
}
}

if (sm2_idx > 0) {
int *groups = OPENSSL_malloc(sizeof(int) * num_groups);
if (groups == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return EXT_RETURN_FAIL;
}

for (i = 0; i < num_groups; i++)
groups[i] = tls1_group_id2nid(pgroups[i], 1);

for (i = sm2_idx; i > 0; i--)
groups[i] = groups[i - 1];

groups[0] = NID_sm2;

if (!tls1_set_groups(&s->ext.supportedgroups,
&s->ext.supportedgroups_len,
groups, num_groups)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
OPENSSL_free(groups);
return EXT_RETURN_FAIL;
}

OPENSSL_free(groups);
tls1_get_supported_groups(s, &pgroups, &num_groups);
}
}
#endif

/* Copy group ID if supported */
for (i = 0; i < num_groups; i++) {
uint16_t ctmp = pgroups[i];
Expand Down
Loading

0 comments on commit a59b923

Please sign in to comment.