Skip to content

Commit 3eef9c8

Browse files
authored
openssl: only free buffers when done (#9309)
1 parent 4246a18 commit 3eef9c8

6 files changed

Lines changed: 97 additions & 25 deletions

File tree

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+
ssl/record/rec_layer_s3.c | 9 +++++++++
15+
ssl/record/record.h | 1 +
16+
ssl/ssl_lib.c | 3 +++
17+
3 files changed, 13 insertions(+)
18+
19+
diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c
20+
index 1db1712a0..525c3abf4 100644
21+
--- a/ssl/record/rec_layer_s3.c
22+
+++ b/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/ssl/record/record.h b/ssl/record/record.h
40+
index af56206e0..513ab3988 100644
41+
--- a/ssl/record/record.h
42+
+++ b/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/ssl/ssl_lib.c b/ssl/ssl_lib.c
52+
index c01ad8291..356d65cb6 100644
53+
--- a/ssl/ssl_lib.c
54+
+++ b/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+

SPECS/openssl/openssl.spec

Lines changed: 8 additions & 3 deletions
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: 30%{?dist}
7+
Release: 31%{?dist}
88
License: OpenSSL
99
Vendor: Microsoft Corporation
1010
Distribution: Mariner
@@ -61,6 +61,7 @@ Patch37: CVE-2023-3817.patch
6161
Patch38: openssl-1.1.1-improve-safety-of-DH.patch
6262
Patch39: openssl-1.1.1-add-null-checks-where-contentinfo-data-can-be-null.patch
6363
Patch40: openssl-1.1.1-Fix-unconstrained-session-cache-growth-in-TLSv1.3.patch
64+
Patch41: openssl-1.1.1-Only-free-the-read-buffers-if-we-re-not-using-them.patch
6465
BuildRequires: perl-Test-Warnings
6566
BuildRequires: perl-Text-Template
6667
BuildRequires: perl(FindBin)
@@ -174,6 +175,7 @@ cp %{SOURCE4} test/
174175
%patch38 -p1
175176
%patch39 -p1
176177
%patch40 -p1
178+
%patch41 -p1
177179

178180
%build
179181
# Add -Wa,--noexecstack here so that libcrypto's assembler modules will be
@@ -363,8 +365,11 @@ rm -f %{buildroot}%{_sysconfdir}/pki/tls/ct_log_list.cnf.dist
363365
%postun libs -p /sbin/ldconfig
364366

365367
%changelog
366-
* Fri Apr 19 2024 Tobias Brick <tobaisb@microsoft.com> - 1.1.1k-30
367-
* Fix unconstrained session cache growth in TLSv1.3
368+
* Tue Jun 04 2024 Tobias Brick <tobiasb@microsoft.com> - 1.1.1k-31
369+
- Only free the read buffers if we're not using them
370+
371+
* Fri Apr 19 2024 Tobias Brick <tobiasb@microsoft.com> - 1.1.1k-30
372+
- Fix unconstrained session cache growth in TLSv1.3
368373

369374
* Wed Feb 14 2024 Tobias Brick <tobiasb@microsoft.com> - 1.1.1k-29
370375
- Introduce patch to correctly address NULL ContentInfo data

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-30.cm2.aarch64.rpm
169-
openssl-devel-1.1.1k-30.cm2.aarch64.rpm
170-
openssl-libs-1.1.1k-30.cm2.aarch64.rpm
171-
openssl-perl-1.1.1k-30.cm2.aarch64.rpm
172-
openssl-static-1.1.1k-30.cm2.aarch64.rpm
168+
openssl-1.1.1k-31.cm2.aarch64.rpm
169+
openssl-devel-1.1.1k-31.cm2.aarch64.rpm
170+
openssl-libs-1.1.1k-31.cm2.aarch64.rpm
171+
openssl-perl-1.1.1k-31.cm2.aarch64.rpm
172+
openssl-static-1.1.1k-31.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-30.cm2.x86_64.rpm
169-
openssl-devel-1.1.1k-30.cm2.x86_64.rpm
170-
openssl-libs-1.1.1k-30.cm2.x86_64.rpm
171-
openssl-perl-1.1.1k-30.cm2.x86_64.rpm
172-
openssl-static-1.1.1k-30.cm2.x86_64.rpm
168+
openssl-1.1.1k-31.cm2.x86_64.rpm
169+
openssl-devel-1.1.1k-31.cm2.x86_64.rpm
170+
openssl-libs-1.1.1k-31.cm2.x86_64.rpm
171+
openssl-perl-1.1.1k-31.cm2.x86_64.rpm
172+
openssl-static-1.1.1k-31.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-30.cm2.aarch64.rpm
274-
openssl-debuginfo-1.1.1k-30.cm2.aarch64.rpm
275-
openssl-devel-1.1.1k-30.cm2.aarch64.rpm
276-
openssl-libs-1.1.1k-30.cm2.aarch64.rpm
277-
openssl-perl-1.1.1k-30.cm2.aarch64.rpm
278-
openssl-static-1.1.1k-30.cm2.aarch64.rpm
273+
openssl-1.1.1k-31.cm2.aarch64.rpm
274+
openssl-debuginfo-1.1.1k-31.cm2.aarch64.rpm
275+
openssl-devel-1.1.1k-31.cm2.aarch64.rpm
276+
openssl-libs-1.1.1k-31.cm2.aarch64.rpm
277+
openssl-perl-1.1.1k-31.cm2.aarch64.rpm
278+
openssl-static-1.1.1k-31.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-30.cm2.x86_64.rpm
280-
openssl-debuginfo-1.1.1k-30.cm2.x86_64.rpm
281-
openssl-devel-1.1.1k-30.cm2.x86_64.rpm
282-
openssl-libs-1.1.1k-30.cm2.x86_64.rpm
283-
openssl-perl-1.1.1k-30.cm2.x86_64.rpm
284-
openssl-static-1.1.1k-30.cm2.x86_64.rpm
279+
openssl-1.1.1k-31.cm2.x86_64.rpm
280+
openssl-debuginfo-1.1.1k-31.cm2.x86_64.rpm
281+
openssl-devel-1.1.1k-31.cm2.x86_64.rpm
282+
openssl-libs-1.1.1k-31.cm2.x86_64.rpm
283+
openssl-perl-1.1.1k-31.cm2.x86_64.rpm
284+
openssl-static-1.1.1k-31.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)