Skip to content

Commit 8819ad7

Browse files
[AUTO-CHERRYPICK] [High] patch vendored openssl code in edk2 in 3.0 - branch 3.0-dev (#13224)
Co-authored-by: Tobias Brick <39196763+tobiasb-ms@users.noreply.github.com>
1 parent 0838944 commit 8819ad7

5 files changed

Lines changed: 110 additions & 28 deletions

File tree

SPECS-SIGNED/edk2-hvloader-signed/edk2-hvloader-signed.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Summary: Signed HvLoader.efi for %{buildarch} systems
1212
Name: edk2-hvloader-signed-%{buildarch}
1313
Version: %{GITDATE}git%{GITCOMMIT}
14-
Release: 4%{?dist}
14+
Release: 5%{?dist}
1515
License: MIT
1616
Vendor: Microsoft Corporation
1717
Distribution: Azure Linux
@@ -74,6 +74,9 @@ popd
7474
/boot/efi/HvLoader.efi
7575

7676
%changelog
77+
* Wed Mar 26 2025 Tobias Brick <tobiasb@microsoft.com> - 20240524git3e722403cd16-5
78+
- Bump release for consistency with edk2 spec.
79+
7780
* Fri Jan 24 2025 Cameron Baird <cameronbaird@microsoft.com> - 20240524git3e722403cd16-4
7881
- Original version for Azure Linux.
7982
- License verified

SPECS/edk2/CVE-2022-3996.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Reviewed-by: Tomas Mraz <tomas@openssl.org>
1616

1717
(cherry picked from commit 4d0340a6d2f327700a059f0b8f954d6160f8eef5)
1818
---
19-
crypto/x509/pcy_map.c | 4 ----
19+
CryptoPkg/Library/OpensslLib/openssl/crypto/x509/pcy_map.c | 4 ----
2020
1 file changed, 4 deletions(-)
2121

22-
diff --git a/crypto/x509/pcy_map.c b/crypto/x509/pcy_map.c
22+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/pcy_map.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/pcy_map.c
2323
index 05406c6493fce..60dfd1e3203b0 100644
24-
--- a/crypto/x509/pcy_map.c
25-
+++ b/crypto/x509/pcy_map.c
24+
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/pcy_map.c
25+
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/pcy_map.c
2626
@@ -73,10 +73,6 @@ int ossl_policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
2727

2828
ret = 1;
@@ -33,4 +33,4 @@ index 05406c6493fce..60dfd1e3203b0 100644
3333
- }
3434
sk_POLICY_MAPPING_pop_free(maps, POLICY_MAPPING_free);
3535
return ret;
36-
36+

SPECS/edk2/CVE-2024-6119.patch

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ Reviewed-by: Richard Levitte <levitte@openssl.org>
2121
Reviewed-by: Tomas Mraz <tomas@openssl.org>
2222
(cherry picked from commit 0890cd13d40fbc98f655f3974f466769caa83680)
2323
---
24-
crypto/x509/v3_utl.c | 78 +++++++++++++------
25-
test/recipes/25-test_eai_data.t | 12 ++-
26-
test/recipes/25-test_eai_data/kdc-cert.pem | 21 +++++
27-
.../25-test_eai_data/kdc-root-cert.pem | 16 ++++
28-
test/recipes/25-test_eai_data/kdc.sh | 41 ++++++++++
24+
CryptoPkg/Library/OpensslLib/openssl/crypto/x509/v3_utl.c | 78 +++++++++++++------
25+
CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data.t | 12 ++-
26+
CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-cert.pem | 21 +++++
27+
.../25-test_eai_data/kdc-root-cert.pem | 16 ++++
28+
CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc.sh | 41 ++++++++++
2929
5 files changed, 142 insertions(+), 26 deletions(-)
3030
create mode 100644 test/recipes/25-test_eai_data/kdc-cert.pem
3131
create mode 100644 test/recipes/25-test_eai_data/kdc-root-cert.pem
3232
create mode 100755 test/recipes/25-test_eai_data/kdc.sh
3333

34-
diff --git a/crypto/x509/v3_utl.c b/crypto/x509/v3_utl.c
34+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/v3_utl.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/v3_utl.c
3535
index 1a18174995196..a09414c972fa8 100644
36-
--- a/crypto/x509/v3_utl.c
37-
+++ b/crypto/x509/v3_utl.c
36+
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/v3_utl.c
37+
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509/v3_utl.c
3838
@@ -916,36 +916,64 @@ static int do_x509_check(X509 *x, const char *chk, size_t chklen,
3939
ASN1_STRING *cstr;
4040

@@ -125,10 +125,10 @@ index 1a18174995196..a09414c972fa8 100644
125125
/* Positive on success, negative on error! */
126126
if ((rv = do_check_string(cstr, alt_type, equal, flags,
127127
chk, chklen, peername)) != 0)
128-
diff --git a/test/recipes/25-test_eai_data.t b/test/recipes/25-test_eai_data.t
128+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data.t b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data.t
129129
index 522982ddfb802..e18735d89aadf 100644
130-
--- a/test/recipes/25-test_eai_data.t
131-
+++ b/test/recipes/25-test_eai_data.t
130+
--- a/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data.t
131+
+++ b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data.t
132132
@@ -21,16 +21,18 @@ setup("test_eai_data");
133133
#./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/utf8_chain.pem test/recipes/25-test_eai_data/ascii_leaf.pem
134134
#./util/wrap.pl apps/openssl verify -nameopt utf8 -no_check_time -CAfile test/recipes/25-test_eai_data/ascii_chain.pem test/recipes/25-test_eai_data/utf8_leaf.pem
@@ -168,11 +168,11 @@ index 522982ddfb802..e18735d89aadf 100644
168168
#Check that we get the expected failure return code
169169
with({ exit_checker => sub { return shift == 2; } },
170170
sub {
171-
diff --git a/test/recipes/25-test_eai_data/kdc-cert.pem b/test/recipes/25-test_eai_data/kdc-cert.pem
171+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-cert.pem b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-cert.pem
172172
new file mode 100644
173173
index 0000000000000..e8a2c6f55d459
174174
--- /dev/null
175-
+++ b/test/recipes/25-test_eai_data/kdc-cert.pem
175+
+++ b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-cert.pem
176176
@@ -0,0 +1,21 @@
177177
+-----BEGIN CERTIFICATE-----
178178
+MIIDbDCCAlSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARSb290
@@ -195,11 +195,11 @@ index 0000000000000..e8a2c6f55d459
195195
+0fTCOBEMjIETDsrA70OxAMu4V16nrWZdJdvzblS2qrt97Omkj+2kiPAJFB76RpwI
196196
+oDQ9fKfUOAmUFth2/R/eGA==
197197
+-----END CERTIFICATE-----
198-
diff --git a/test/recipes/25-test_eai_data/kdc-root-cert.pem b/test/recipes/25-test_eai_data/kdc-root-cert.pem
198+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-root-cert.pem b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-root-cert.pem
199199
new file mode 100644
200200
index 0000000000000..a74c96bf31469
201201
--- /dev/null
202-
+++ b/test/recipes/25-test_eai_data/kdc-root-cert.pem
202+
+++ b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc-root-cert.pem
203203
@@ -0,0 +1,16 @@
204204
+-----BEGIN CERTIFICATE-----
205205
+MIICnDCCAYQCCQCBswYcrlZSHjANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARS
@@ -217,11 +217,11 @@ index 0000000000000..a74c96bf31469
217217
+7rFGM5AOevb4U8ddop8A3D/kX0wcCAIBF6jCNk3uEJ57jVcagL04kPnVfdRiedTS
218218
+vfq1DRNcD29d1H/9u0fHdSn1/+8Ep3X+afQ3C6//5NvOEaXcIGO4QSwkprQydfv8
219219
+-----END CERTIFICATE-----
220-
diff --git a/test/recipes/25-test_eai_data/kdc.sh b/test/recipes/25-test_eai_data/kdc.sh
220+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc.sh b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc.sh
221221
new file mode 100755
222222
index 0000000000000..7a8dbc719fb71
223223
--- /dev/null
224-
+++ b/test/recipes/25-test_eai_data/kdc.sh
224+
+++ b/CryptoPkg/Library/OpensslLib/openssl/test/recipes/25-test_eai_data/kdc.sh
225225
@@ -0,0 +1,41 @@
226226
+#! /usr/bin/env bash
227227
+

SPECS/edk2/edk2.spec

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ExclusiveArch: x86_64
5555

5656
Name: edk2
5757
Version: %{GITDATE}git%{GITCOMMIT}
58-
Release: 4%{?dist}
58+
Release: 5%{?dist}
5959
Summary: UEFI firmware for 64-bit virtual machines
6060
License: Apache-2.0 AND (BSD-2-Clause OR GPL-2.0-or-later) AND BSD-2-Clause-Patent AND BSD-3-Clause AND BSD-4-Clause AND ISC AND MIT AND LicenseRef-Fedora-Public-Domain
6161
URL: http://www.tianocore.org
@@ -129,8 +129,11 @@ Patch0017: 0017-silence-.-has-a-LOAD-segment-with-RWX-permissions-wa.patch
129129
%endif
130130
Patch0018: 0018-NetworkPkg-TcpDxe-Fixed-system-stuck-on-PXE-boot-flo.patch
131131
Patch0019: 0019-NetworkPkg-DxeNetLib-adjust-PseudoRandom-error-loggi.patch
132+
133+
# Patches for the vendored OpenSSL are in the range from 1000 to 1999 (inclusive).
132134
Patch1000: CVE-2022-3996.patch
133135
Patch1001: CVE-2024-6119.patch
136+
Patch1002: vendored-openssl-1.1.1-Only-free-the-read-buffers-if-we-re-not-using-them.patch
134137

135138
# python3-devel and libuuid-devel are required for building tools.
136139
# python3-devel is also needed for varstore template generation and
@@ -338,11 +341,17 @@ git config am.keepcr true
338341
# -M Apply patches up to 999
339342
%autopatch -M 999
340343

344+
# Unpack the vendored OpenSSL tarball. This tarball has a '.git' directory
345+
# which will confuse the git repo we unpack it into, so exclude that.
346+
# Then add it to the git index so that we can use autopatch, which
347+
# uses git am since we set it up that way initially.
348+
# Only apply patches between 1000 and 1999 (inclusive).
349+
tar -C CryptoPkg/Library/OpensslLib -a -f %{SOURCE2} -x --exclude '.git'
350+
git add .
351+
git commit -m 'add vendored openssl'
352+
%autopatch -p1 -m 1000 -M 1999
353+
341354
cp -a -- %{SOURCE1} .
342-
tar -C CryptoPkg/Library/OpensslLib -a -f %{SOURCE2} -x
343-
# Need to patch CVE-2022-3996 in the bundled openssl
344-
(cd CryptoPkg/Library/OpensslLib/openssl && patch -p1 ) < %{PATCH1000}
345-
(cd CryptoPkg/Library/OpensslLib/openssl && patch -p1 ) < %{PATCH1001}
346355

347356
# extract softfloat into place
348357
tar -xf %{SOURCE3} --strip-components=1 --directory ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3/
@@ -786,6 +795,9 @@ done
786795
/boot/efi/HvLoader.efi
787796

788797
%changelog
798+
* Tue Mar 25 2025 Tobias Brick <tobiasb@microsoft.com> - 20240524git3e722403cd16-5
799+
- Patch vendored openssl to only free read buffers if not in use.
800+
789801
* Wed Sep 25 2024 Cameron Baird <cameronbaird@microsoft.com> - 20240524git3e722403cd16-4
790802
- Package license for edk2-hvloader
791803

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
From f7a045f3143fc6da2ee66bf52d8df04829590dd4 Mon Sep 17 00:00:00 2001
2+
From: Watson Ladd <watsonbladd@gmail.com>
3+
Date: Wed, 24 Apr 2024 11:26:56 +0100
4+
Subject: [PATCH] Only free the read buffers if we're not using them
5+
6+
If we're part way through processing a record, or the application has
7+
not released all the records then we should not free our buffer because
8+
they are still needed.
9+
10+
Reviewed-by: Tomas Mraz <tomas@openssl.org>
11+
Reviewed-by: Neil Horman <nhorman@openssl.org>
12+
Reviewed-by: Matt Caswell <matt@openssl.org>
13+
---
14+
CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c | 9 +++++++++
15+
CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h | 1 +
16+
CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c | 3 +++
17+
3 files changed, 13 insertions(+)
18+
19+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c
20+
index 1db1712a0..525c3abf4 100644
21+
--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c
22+
+++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c
23+
@@ -81,6 +81,15 @@ int RECORD_LAYER_read_pending(const RECORD_LAYER *rl)
24+
return SSL3_BUFFER_get_left(&rl->rbuf) != 0;
25+
}
26+
27+
+int RECORD_LAYER_data_present(const RECORD_LAYER *rl)
28+
+{
29+
+ if (rl->rstate == SSL_ST_READ_BODY)
30+
+ return 1;
31+
+ if (RECORD_LAYER_processed_read_pending(rl))
32+
+ return 1;
33+
+ return 0;
34+
+}
35+
+
36+
/* Checks if we have decrypted unread record data pending */
37+
int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl)
38+
{
39+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h
40+
index af56206e0..513ab3988 100644
41+
--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h
42+
+++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h
43+
@@ -197,6 +197,7 @@ void RECORD_LAYER_release(RECORD_LAYER *rl);
44+
int RECORD_LAYER_read_pending(const RECORD_LAYER *rl);
45+
int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl);
46+
int RECORD_LAYER_write_pending(const RECORD_LAYER *rl);
47+
+int RECORD_LAYER_data_present(const RECORD_LAYER *rl);
48+
void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl);
49+
void RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl);
50+
int RECORD_LAYER_is_sslv2_record(RECORD_LAYER *rl);
51+
diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c b/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c
52+
index c01ad8291..356d65cb6 100644
53+
--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c
54+
+++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c
55+
@@ -5248,6 +5248,9 @@ int SSL_free_buffers(SSL *ssl)
56+
if (RECORD_LAYER_read_pending(rl) || RECORD_LAYER_write_pending(rl))
57+
return 0;
58+
59+
+ if (RECORD_LAYER_data_present(rl))
60+
+ return 0;
61+
+
62+
RECORD_LAYER_release(rl);
63+
return 1;
64+
}
65+
--
66+
2.33.8
67+

0 commit comments

Comments
 (0)