Skip to content

Commit 5e921ee

Browse files
[AUTO-CHERRYPICK] Patch CVE-2024-5535 in openssl - branch main (#9905)
1 parent 8fbdbff commit 5e921ee

6 files changed

Lines changed: 135 additions & 23 deletions

File tree

SPECS/openssl/CVE-2024-5535.patch

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
From cf6f91f6121f4db167405db2f0de410a456f260c Mon Sep 17 00:00:00 2001
2+
From: Matt Caswell <matt@openssl.org>
3+
Date: Fri, 31 May 2024 11:14:33 +0100
4+
Subject: [PATCH] Fix SSL_select_next_proto
5+
6+
Ensure that the provided client list is non-NULL and starts with a valid
7+
entry. When called from the ALPN callback the client list should already
8+
have been validated by OpenSSL so this should not cause a problem. When
9+
called from the NPN callback the client list is locally configured and
10+
will not have already been validated. Therefore SSL_select_next_proto
11+
should not assume that it is correctly formatted.
12+
13+
We implement stricter checking of the client protocol list. We also do the
14+
same for the server list while we are about it.
15+
16+
CVE-2024-5535
17+
18+
Reviewed-by: Neil Horman <nhorman@openssl.org>
19+
Reviewed-by: Tomas Mraz <tomas@openssl.org>
20+
(Merged from https://github.com/openssl/openssl/pull/24718)
21+
22+
(cherry picked from commit 4ada436a1946cbb24db5ab4ca082b69c1bc10f37)
23+
---
24+
ssl/ssl_lib.c | 63 ++++++++++++++++++++++++++++++++-------------------
25+
1 file changed, 40 insertions(+), 23 deletions(-)
26+
27+
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
28+
index cb4e006ea7a37..e628140dfae9a 100644
29+
--- a/ssl/ssl_lib.c
30+
+++ b/ssl/ssl_lib.c
31+
@@ -2952,37 +2952,54 @@ int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
32+
unsigned int server_len,
33+
const unsigned char *client, unsigned int client_len)
34+
{
35+
- unsigned int i, j;
36+
- const unsigned char *result;
37+
- int status = OPENSSL_NPN_UNSUPPORTED;
38+
+ PACKET cpkt, csubpkt, spkt, ssubpkt;
39+
+
40+
+ if (!PACKET_buf_init(&cpkt, client, client_len)
41+
+ || !PACKET_get_length_prefixed_1(&cpkt, &csubpkt)
42+
+ || PACKET_remaining(&csubpkt) == 0) {
43+
+ *out = NULL;
44+
+ *outlen = 0;
45+
+ return OPENSSL_NPN_NO_OVERLAP;
46+
+ }
47+
+
48+
+ /*
49+
+ * Set the default opportunistic protocol. Will be overwritten if we find
50+
+ * a match.
51+
+ */
52+
+ *out = (unsigned char *)PACKET_data(&csubpkt);
53+
+ *outlen = (unsigned char)PACKET_remaining(&csubpkt);
54+
55+
/*
56+
* For each protocol in server preference order, see if we support it.
57+
*/
58+
- for (i = 0; i < server_len;) {
59+
- for (j = 0; j < client_len;) {
60+
- if (server[i] == client[j] &&
61+
- memcmp(&server[i + 1], &client[j + 1], server[i]) == 0) {
62+
- /* We found a match */
63+
- result = &server[i];
64+
- status = OPENSSL_NPN_NEGOTIATED;
65+
- goto found;
66+
+ if (PACKET_buf_init(&spkt, server, server_len)) {
67+
+ while (PACKET_get_length_prefixed_1(&spkt, &ssubpkt)) {
68+
+ if (PACKET_remaining(&ssubpkt) == 0)
69+
+ continue; /* Invalid - ignore it */
70+
+ if (PACKET_buf_init(&cpkt, client, client_len)) {
71+
+ while (PACKET_get_length_prefixed_1(&cpkt, &csubpkt)) {
72+
+ if (PACKET_equal(&csubpkt, PACKET_data(&ssubpkt),
73+
+ PACKET_remaining(&ssubpkt))) {
74+
+ /* We found a match */
75+
+ *out = (unsigned char *)PACKET_data(&ssubpkt);
76+
+ *outlen = (unsigned char)PACKET_remaining(&ssubpkt);
77+
+ return OPENSSL_NPN_NEGOTIATED;
78+
+ }
79+
+ }
80+
+ /* Ignore spurious trailing bytes in the client list */
81+
+ } else {
82+
+ /* This should never happen */
83+
+ return OPENSSL_NPN_NO_OVERLAP;
84+
}
85+
- j += client[j];
86+
- j++;
87+
}
88+
- i += server[i];
89+
- i++;
90+
+ /* Ignore spurious trailing bytes in the server list */
91+
}
92+
93+
- /* There's no overlap between our protocols and the server's list. */
94+
- result = client;
95+
- status = OPENSSL_NPN_NO_OVERLAP;
96+
-
97+
- found:
98+
- *out = (unsigned char *)result + 1;
99+
- *outlen = result[0];
100+
- return status;
101+
+ /*
102+
+ * There's no overlap between our protocols and the server's list. We use
103+
+ * the default opportunistic protocol selected earlier
104+
+ */
105+
+ return OPENSSL_NPN_NO_OVERLAP;
106+
}
107+
108+
#ifndef OPENSSL_NO_NEXTPROTONEG

SPECS/openssl/openssl.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Summary: Utilities from the general purpose cryptography library with TLS implementation
55
Name: openssl
66
Version: 1.1.1k
7-
Release: 33%{?dist}
7+
Release: 34%{?dist}
88
License: OpenSSL
99
Vendor: Microsoft Corporation
1010
Distribution: Mariner
@@ -64,6 +64,7 @@ Patch40: openssl-1.1.1-Fix-unconstrained-session-cache-growth-in-TLSv1.3.
6464
Patch41: openssl-1.1.1-pkcs1-implicit-rejection.patch
6565
Patch42: openssl-1.1.1-Only-free-the-read-buffers-if-we-re-not-using-them.patch
6666
Patch43: openssl-1.1.1-jitterentropy-fix-intermittent-fips-selftest-failure.patch
67+
Patch44: CVE-2024-5535.patch
6768
BuildRequires: perl-Test-Warnings
6869
BuildRequires: perl-Text-Template
6970
BuildRequires: perl(FindBin)
@@ -369,6 +370,9 @@ rm -f %{buildroot}%{_sysconfdir}/pki/tls/ct_log_list.cnf.dist
369370
%postun libs -p /sbin/ldconfig
370371

371372
%changelog
373+
* Mon Jul 22 2024 Suresh Thelkar <sthelkar@microsoft.com> - 1.1.1k-34
374+
- Patch CVE-2024-5535
375+
372376
* Tue Jul 16 2024 Tobias Brick <tobiasb@microsoft.com> - 1.1.1k-33
373377
- Fix intermittent FIPS selftest failures in jitterentropy module
374378

toolkit/resources/manifests/package/pkggen_core_aarch64.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ texinfo-6.8-1.cm2.aarch64.rpm
165165
gtk-doc-1.33.2-1.cm2.noarch.rpm
166166
autoconf-2.71-3.cm2.noarch.rpm
167167
automake-1.16.5-1.cm2.noarch.rpm
168-
openssl-1.1.1k-33.cm2.aarch64.rpm
169-
openssl-devel-1.1.1k-33.cm2.aarch64.rpm
170-
openssl-libs-1.1.1k-33.cm2.aarch64.rpm
171-
openssl-perl-1.1.1k-33.cm2.aarch64.rpm
172-
openssl-static-1.1.1k-33.cm2.aarch64.rpm
168+
openssl-1.1.1k-34.cm2.aarch64.rpm
169+
openssl-devel-1.1.1k-34.cm2.aarch64.rpm
170+
openssl-libs-1.1.1k-34.cm2.aarch64.rpm
171+
openssl-perl-1.1.1k-34.cm2.aarch64.rpm
172+
openssl-static-1.1.1k-34.cm2.aarch64.rpm
173173
libcap-2.60-2.cm2.aarch64.rpm
174174
libcap-devel-2.60-2.cm2.aarch64.rpm
175175
debugedit-5.0-2.cm2.aarch64.rpm

toolkit/resources/manifests/package/pkggen_core_x86_64.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ texinfo-6.8-1.cm2.x86_64.rpm
165165
gtk-doc-1.33.2-1.cm2.noarch.rpm
166166
autoconf-2.71-3.cm2.noarch.rpm
167167
automake-1.16.5-1.cm2.noarch.rpm
168-
openssl-1.1.1k-33.cm2.x86_64.rpm
169-
openssl-devel-1.1.1k-33.cm2.x86_64.rpm
170-
openssl-libs-1.1.1k-33.cm2.x86_64.rpm
171-
openssl-perl-1.1.1k-33.cm2.x86_64.rpm
172-
openssl-static-1.1.1k-33.cm2.x86_64.rpm
168+
openssl-1.1.1k-34.cm2.x86_64.rpm
169+
openssl-devel-1.1.1k-34.cm2.x86_64.rpm
170+
openssl-libs-1.1.1k-34.cm2.x86_64.rpm
171+
openssl-perl-1.1.1k-34.cm2.x86_64.rpm
172+
openssl-static-1.1.1k-34.cm2.x86_64.rpm
173173
libcap-2.60-2.cm2.x86_64.rpm
174174
libcap-devel-2.60-2.cm2.x86_64.rpm
175175
debugedit-5.0-2.cm2.x86_64.rpm

toolkit/resources/manifests/package/toolchain_aarch64.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ npth-1.6-4.cm2.aarch64.rpm
270270
npth-debuginfo-1.6-4.cm2.aarch64.rpm
271271
npth-devel-1.6-4.cm2.aarch64.rpm
272272
ntsysv-1.20-4.cm2.aarch64.rpm
273-
openssl-1.1.1k-33.cm2.aarch64.rpm
274-
openssl-debuginfo-1.1.1k-33.cm2.aarch64.rpm
275-
openssl-devel-1.1.1k-33.cm2.aarch64.rpm
276-
openssl-libs-1.1.1k-33.cm2.aarch64.rpm
277-
openssl-perl-1.1.1k-33.cm2.aarch64.rpm
278-
openssl-static-1.1.1k-33.cm2.aarch64.rpm
273+
openssl-1.1.1k-34.cm2.aarch64.rpm
274+
openssl-debuginfo-1.1.1k-34.cm2.aarch64.rpm
275+
openssl-devel-1.1.1k-34.cm2.aarch64.rpm
276+
openssl-libs-1.1.1k-34.cm2.aarch64.rpm
277+
openssl-perl-1.1.1k-34.cm2.aarch64.rpm
278+
openssl-static-1.1.1k-34.cm2.aarch64.rpm
279279
p11-kit-0.24.1-1.cm2.aarch64.rpm
280280
p11-kit-debuginfo-0.24.1-1.cm2.aarch64.rpm
281281
p11-kit-devel-0.24.1-1.cm2.aarch64.rpm

toolkit/resources/manifests/package/toolchain_x86_64.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ npth-1.6-4.cm2.x86_64.rpm
276276
npth-debuginfo-1.6-4.cm2.x86_64.rpm
277277
npth-devel-1.6-4.cm2.x86_64.rpm
278278
ntsysv-1.20-4.cm2.x86_64.rpm
279-
openssl-1.1.1k-33.cm2.x86_64.rpm
280-
openssl-debuginfo-1.1.1k-33.cm2.x86_64.rpm
281-
openssl-devel-1.1.1k-33.cm2.x86_64.rpm
282-
openssl-libs-1.1.1k-33.cm2.x86_64.rpm
283-
openssl-perl-1.1.1k-33.cm2.x86_64.rpm
284-
openssl-static-1.1.1k-33.cm2.x86_64.rpm
279+
openssl-1.1.1k-34.cm2.x86_64.rpm
280+
openssl-debuginfo-1.1.1k-34.cm2.x86_64.rpm
281+
openssl-devel-1.1.1k-34.cm2.x86_64.rpm
282+
openssl-libs-1.1.1k-34.cm2.x86_64.rpm
283+
openssl-perl-1.1.1k-34.cm2.x86_64.rpm
284+
openssl-static-1.1.1k-34.cm2.x86_64.rpm
285285
p11-kit-0.24.1-1.cm2.x86_64.rpm
286286
p11-kit-debuginfo-0.24.1-1.cm2.x86_64.rpm
287287
p11-kit-devel-0.24.1-1.cm2.x86_64.rpm

0 commit comments

Comments
 (0)