Skip to content

Commit e0e631b

Browse files
authored
Merge pull request #797 from span786/PA-6132-backport-open-ssl-1-1-1-for-agent-runtime-7-x
PA-6132: Back-Port OpenSSL 1.1.1 for agent-runtime-7.x
2 parents 8474070 + 047418e commit e0e631b

8 files changed

+611
-19
lines changed

configs/components/openssl-1.1.1-fips.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1-fips-spec-file.patch'
2525
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1-fips-remove-env-check.patch'
2626
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1l-sm2-plaintext.patch'
27+
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1k-CVE-2023-3446-fips.patch'
28+
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1k-CVE-2023-5678-fips.patch'
29+
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1k-CVE-2024-0727-fips.patch'
2730

2831
if platform.name =~ /-7-/
2932
pkg.add_source 'file://resources/patches/openssl/openssl-1.1.1-fips-post-rand.patch'
@@ -55,7 +58,10 @@
5558
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1-fips-force-fips-mode.patch && cd -",
5659
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1-fips-spec-file.patch && cd -",
5760
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1-fips-remove-env-check.patch && cd -",
58-
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1l-sm2-plaintext.patch && cd -"
61+
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1l-sm2-plaintext.patch && cd -",
62+
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1k-CVE-2023-3446-fips.patch && cd -",
63+
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1k-CVE-2023-5678-fips.patch && cd -",
64+
"cd openssl-#{pkg.get_version} && /usr/bin/patch --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../openssl-1.1.1k-CVE-2024-0727-fips.patch && cd -"
5965
]
6066
end
6167

configs/components/openssl-1.1.1.rb

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
end
8888
end
8989

90+
pkg.apply_patch 'resources/patches/openssl/CVE-2023-5678.patch'
91+
pkg.apply_patch 'resources/patches/openssl/CVE-2024-0727.patch'
92+
9093
####################
9194
# BUILD REQUIREMENTS
9295
####################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
Backport of:
2+
3+
From db925ae2e65d0d925adef429afc37f75bd1c2017 Mon Sep 17 00:00:00 2001
4+
From: Richard Levitte <[email protected]>
5+
Date: Fri, 20 Oct 2023 09:18:19 +0200
6+
Subject: [PATCH] Make DH_check_pub_key() and DH_generate_key() safer yet
7+
8+
We already check for an excessively large P in DH_generate_key(), but not in
9+
DH_check_pub_key(), and none of them check for an excessively large Q.
10+
11+
This change adds all the missing excessive size checks of P and Q.
12+
13+
It's to be noted that behaviours surrounding excessively sized P and Q
14+
differ. DH_check() raises an error on the excessively sized P, but only
15+
sets a flag for the excessively sized Q. This behaviour is mimicked in
16+
DH_check_pub_key().
17+
18+
Reviewed-by: Tomas Mraz <[email protected]>
19+
Reviewed-by: Matt Caswell <[email protected]>
20+
Reviewed-by: Hugo Landau <[email protected]>
21+
(Merged from https://github.com/openssl/openssl/pull/22518)
22+
23+
(cherry picked from commit ddeb4b6c6d527e54ce9a99cba785c0f7776e54b6)
24+
---
25+
crypto/dh/dh_check.c | 12 ++++++++++++
26+
crypto/dh/dh_err.c | 3 ++-
27+
crypto/dh/dh_key.c | 12 ++++++++++++
28+
crypto/err/openssl.txt | 1 +
29+
include/crypto/dherr.h | 2 +-
30+
include/openssl/dh.h | 6 +++---
31+
include/openssl/dherr.h | 3 ++-
32+
7 files changed, 33 insertions(+), 6 deletions(-)
33+
34+
--- a/crypto/dh/dh_check.c
35+
+++ b/crypto/dh/dh_check.c
36+
@@ -201,6 +201,19 @@ int DH_check_pub_key(const DH *dh, const
37+
if (ctx == NULL)
38+
goto err;
39+
BN_CTX_start(ctx);
40+
+
41+
+ /* Don't do any checks at all with an excessively large modulus */
42+
+ if (BN_num_bits(dh->p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) {
43+
+ DHerr(DH_F_DH_CHECK, DH_R_MODULUS_TOO_LARGE);
44+
+ *ret = DH_MODULUS_TOO_LARGE | DH_CHECK_PUBKEY_INVALID;
45+
+ goto err;
46+
+ }
47+
+
48+
+ if (dh->q != NULL && BN_ucmp(dh->p, dh->q) < 0) {
49+
+ *ret |= DH_CHECK_INVALID_Q_VALUE | DH_CHECK_PUBKEY_INVALID;
50+
+ goto out;
51+
+ }
52+
+
53+
tmp = BN_CTX_get(ctx);
54+
if (tmp == NULL || !BN_set_word(tmp, 1))
55+
goto err;
56+
@@ -219,6 +232,7 @@ int DH_check_pub_key(const DH *dh, const
57+
*ret |= DH_CHECK_PUBKEY_INVALID;
58+
}
59+
60+
+ out:
61+
ok = 1;
62+
err:
63+
BN_CTX_end(ctx);
64+
--- a/crypto/dh/dh_err.c
65+
+++ b/crypto/dh/dh_err.c
66+
@@ -82,6 +82,7 @@ static const ERR_STRING_DATA DH_str_reas
67+
{ERR_PACK(ERR_LIB_DH, 0, DH_R_PARAMETER_ENCODING_ERROR),
68+
"parameter encoding error"},
69+
{ERR_PACK(ERR_LIB_DH, 0, DH_R_PEER_KEY_ERROR), "peer key error"},
70+
+ {ERR_PACK(ERR_LIB_DH, 0, DH_R_Q_TOO_LARGE), "q too large"},
71+
{ERR_PACK(ERR_LIB_DH, 0, DH_R_SHARED_INFO_ERROR), "shared info error"},
72+
{ERR_PACK(ERR_LIB_DH, 0, DH_R_UNABLE_TO_CHECK_GENERATOR),
73+
"unable to check generator"},
74+
--- a/crypto/dh/dh_key.c
75+
+++ b/crypto/dh/dh_key.c
76+
@@ -87,6 +87,12 @@ static int generate_key(DH *dh)
77+
return 0;
78+
}
79+
80+
+ if (dh->q != NULL
81+
+ && BN_num_bits(dh->q) > OPENSSL_DH_MAX_MODULUS_BITS) {
82+
+ DHerr(DH_F_GENERATE_KEY, DH_R_Q_TOO_LARGE);
83+
+ return 0;
84+
+ }
85+
+
86+
ctx = BN_CTX_new();
87+
if (ctx == NULL)
88+
goto err;
89+
@@ -180,6 +186,12 @@ static int compute_key(unsigned char *ke
90+
goto err;
91+
}
92+
93+
+ if (dh->q != NULL
94+
+ && BN_num_bits(dh->q) > OPENSSL_DH_MAX_MODULUS_BITS) {
95+
+ DHerr(DH_F_COMPUTE_KEY, DH_R_Q_TOO_LARGE);
96+
+ goto err;
97+
+ }
98+
+
99+
ctx = BN_CTX_new();
100+
if (ctx == NULL)
101+
goto err;
102+
--- a/crypto/err/openssl.txt
103+
+++ b/crypto/err/openssl.txt
104+
@@ -2110,6 +2110,7 @@ DH_R_NO_PARAMETERS_SET:107:no parameters
105+
DH_R_NO_PRIVATE_VALUE:100:no private value
106+
DH_R_PARAMETER_ENCODING_ERROR:105:parameter encoding error
107+
DH_R_PEER_KEY_ERROR:111:peer key error
108+
+DH_R_Q_TOO_LARGE:130:q too large
109+
DH_R_SHARED_INFO_ERROR:113:shared info error
110+
DH_R_UNABLE_TO_CHECK_GENERATOR:121:unable to check generator
111+
DSA_R_BAD_Q_VALUE:102:bad q value
112+
--- a/include/openssl/dh.h
113+
+++ b/include/openssl/dh.h
114+
@@ -71,14 +71,16 @@ DECLARE_ASN1_ITEM(DHparams)
115+
/* #define DH_GENERATOR_3 3 */
116+
# define DH_GENERATOR_5 5
117+
118+
-/* DH_check error codes */
119+
+/* DH_check error codes, some of them shared with DH_check_pub_key */
120+
# define DH_CHECK_P_NOT_PRIME 0x01
121+
# define DH_CHECK_P_NOT_SAFE_PRIME 0x02
122+
# define DH_UNABLE_TO_CHECK_GENERATOR 0x04
123+
# define DH_NOT_SUITABLE_GENERATOR 0x08
124+
# define DH_CHECK_Q_NOT_PRIME 0x10
125+
-# define DH_CHECK_INVALID_Q_VALUE 0x20
126+
+# define DH_CHECK_INVALID_Q_VALUE 0x20 /* +DH_check_pub_key */
127+
# define DH_CHECK_INVALID_J_VALUE 0x40
128+
+# define DH_MODULUS_TOO_SMALL 0x80
129+
+# define DH_MODULUS_TOO_LARGE 0x100 /* +DH_check_pub_key */
130+
131+
/* DH_check_pub_key error codes */
132+
# define DH_CHECK_PUBKEY_TOO_SMALL 0x01
133+
--- a/include/openssl/dherr.h
134+
+++ b/include/openssl/dherr.h
135+
@@ -82,6 +82,7 @@ int ERR_load_DH_strings(void);
136+
# define DH_R_NO_PRIVATE_VALUE 100
137+
# define DH_R_PARAMETER_ENCODING_ERROR 105
138+
# define DH_R_PEER_KEY_ERROR 111
139+
+# define DH_R_Q_TOO_LARGE 130
140+
# define DH_R_SHARED_INFO_ERROR 113
141+
# define DH_R_UNABLE_TO_CHECK_GENERATOR 121
142+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
Backport of:
2+
3+
From 09df4395b5071217b76dc7d3d2e630eb8c5a79c2 Mon Sep 17 00:00:00 2001
4+
From: Matt Caswell <[email protected]>
5+
Date: Fri, 19 Jan 2024 11:28:58 +0000
6+
Subject: [PATCH] Add NULL checks where ContentInfo data can be NULL
7+
8+
PKCS12 structures contain PKCS7 ContentInfo fields. These fields are
9+
optional and can be NULL even if the "type" is a valid value. OpenSSL
10+
was not properly accounting for this and a NULL dereference can occur
11+
causing a crash.
12+
13+
CVE-2024-0727
14+
15+
Reviewed-by: Tomas Mraz <[email protected]>
16+
Reviewed-by: Hugo Landau <[email protected]>
17+
Reviewed-by: Neil Horman <[email protected]>
18+
(Merged from https://github.com/openssl/openssl/pull/23362)
19+
20+
(cherry picked from commit d135eeab8a5dbf72b3da5240bab9ddb7678dbd2c)
21+
---
22+
crypto/pkcs12/p12_add.c | 18 ++++++++++++++++++
23+
crypto/pkcs12/p12_mutl.c | 5 +++++
24+
crypto/pkcs12/p12_npas.c | 5 +++--
25+
crypto/pkcs7/pk7_mime.c | 7 +++++--
26+
4 files changed, 31 insertions(+), 4 deletions(-)
27+
28+
--- a/crypto/pkcs12/p12_add.c
29+
+++ b/crypto/pkcs12/p12_add.c
30+
@@ -76,6 +76,13 @@ STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_
31+
PKCS12_R_CONTENT_TYPE_NOT_DATA);
32+
return NULL;
33+
}
34+
+
35+
+ if (p7->d.data == NULL) {
36+
+ PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA,
37+
+ PKCS12_R_DECODE_ERROR);
38+
+ return NULL;
39+
+ }
40+
+
41+
return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS));
42+
}
43+
44+
@@ -132,6 +139,12 @@ STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_
45+
{
46+
if (!PKCS7_type_is_encrypted(p7))
47+
return NULL;
48+
+
49+
+ if (p7->d.encrypted == NULL) {
50+
+ PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA, PKCS12_R_DECODE_ERROR);
51+
+ return NULL;
52+
+ }
53+
+
54+
return PKCS12_item_decrypt_d2i(p7->d.encrypted->enc_data->algorithm,
55+
ASN1_ITEM_rptr(PKCS12_SAFEBAGS),
56+
pass, passlen,
57+
@@ -159,6 +172,13 @@ STACK_OF(PKCS7) *PKCS12_unpack_authsafes
58+
PKCS12_R_CONTENT_TYPE_NOT_DATA);
59+
return NULL;
60+
}
61+
+
62+
+ if (p12->authsafes->d.data == NULL) {
63+
+ PKCS12err(PKCS12_F_PKCS12_UNPACK_AUTHSAFES,
64+
+ PKCS12_R_DECODE_ERROR);
65+
+ return NULL;
66+
+ }
67+
+
68+
return ASN1_item_unpack(p12->authsafes->d.data,
69+
ASN1_ITEM_rptr(PKCS12_AUTHSAFES));
70+
}
71+
--- a/crypto/pkcs12/p12_mutl.c
72+
+++ b/crypto/pkcs12/p12_mutl.c
73+
@@ -93,6 +93,11 @@ static int pkcs12_gen_mac(PKCS12 *p12, c
74+
return 0;
75+
}
76+
77+
+ if (p12->authsafes->d.data == NULL) {
78+
+ PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_DECODE_ERROR);
79+
+ return 0;
80+
+ }
81+
+
82+
salt = p12->mac->salt->data;
83+
saltlen = p12->mac->salt->length;
84+
if (!p12->mac->iter)
85+
--- a/crypto/pkcs12/p12_npas.c
86+
+++ b/crypto/pkcs12/p12_npas.c
87+
@@ -78,8 +78,9 @@ static int newpass_p12(PKCS12 *p12, cons
88+
bags = PKCS12_unpack_p7data(p7);
89+
} else if (bagnid == NID_pkcs7_encrypted) {
90+
bags = PKCS12_unpack_p7encdata(p7, oldpass, -1);
91+
- if (!alg_get(p7->d.encrypted->enc_data->algorithm,
92+
- &pbe_nid, &pbe_iter, &pbe_saltlen))
93+
+ if (p7->d.encrypted == NULL
94+
+ || !alg_get(p7->d.encrypted->enc_data->algorithm,
95+
+ &pbe_nid, &pbe_iter, &pbe_saltlen))
96+
goto err;
97+
} else {
98+
continue;
99+
--- a/crypto/pkcs7/pk7_mime.c
100+
+++ b/crypto/pkcs7/pk7_mime.c
101+
@@ -30,10 +30,13 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p
102+
{
103+
STACK_OF(X509_ALGOR) *mdalgs;
104+
int ctype_nid = OBJ_obj2nid(p7->type);
105+
- if (ctype_nid == NID_pkcs7_signed)
106+
+ if (ctype_nid == NID_pkcs7_signed) {
107+
+ if (p7->d.sign == NULL)
108+
+ return 0;
109+
mdalgs = p7->d.sign->md_algs;
110+
- else
111+
+ } else {
112+
mdalgs = NULL;
113+
+ }
114+
115+
flags ^= SMIME_OLDMIME;
116+

0 commit comments

Comments
 (0)