Skip to content

Commit 7e4d731

Browse files
mattcaswellt8m
authored andcommitted
Fix unconstrained session cache growth in TLSv1.3
In TLSv1.3 we create a new session object for each ticket that we send. We do this by duplicating the original session. If SSL_OP_NO_TICKET is in use then the new session will be added to the session cache. However, if early data is not in use (and therefore anti-replay protection is being used), then multiple threads could be resuming from the same session simultaneously. If this happens and a problem occurs on one of the threads, then the original session object could be marked as not_resumable. When we duplicate the session object this not_resumable status gets copied into the new session object. The new session object is then added to the session cache even though it is not_resumable. Subsequently, another bug means that the session_id_length is set to 0 for sessions that are marked as not_resumable - even though that session is still in the cache. Once this happens the session can never be removed from the cache. When that object gets to be the session cache tail object the cache never shrinks again and grows indefinitely. CVE-2024-2511 Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #24044)
1 parent 031b11a commit 7e4d731

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

ssl/ssl_lib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,9 +3737,10 @@ void ssl_update_cache(SSL *s, int mode)
37373737

37383738
/*
37393739
* If the session_id_length is 0, we are not supposed to cache it, and it
3740-
* would be rather hard to do anyway :-)
3740+
* would be rather hard to do anyway :-). Also if the session has already
3741+
* been marked as not_resumable we should not cache it for later reuse.
37413742
*/
3742-
if (s->session->session_id_length == 0)
3743+
if (s->session->session_id_length == 0 || s->session->not_resumable)
37433744
return;
37443745

37453746
/*

ssl/ssl_sess.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,11 @@ SSL_SESSION *SSL_SESSION_new(void)
154154
return ss;
155155
}
156156

157-
SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src)
158-
{
159-
return ssl_session_dup(src, 1);
160-
}
161-
162157
/*
163158
* Create a new SSL_SESSION and duplicate the contents of |src| into it. If
164159
* ticket == 0 then no ticket information is duplicated, otherwise it is.
165160
*/
166-
SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
161+
static SSL_SESSION *ssl_session_dup_intern(const SSL_SESSION *src, int ticket)
167162
{
168163
SSL_SESSION *dest;
169164

@@ -287,6 +282,27 @@ SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
287282
return NULL;
288283
}
289284

285+
SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src)
286+
{
287+
return ssl_session_dup_intern(src, 1);
288+
}
289+
290+
/*
291+
* Used internally when duplicating a session which might be already shared.
292+
* We will have resumed the original session. Subsequently we might have marked
293+
* it as non-resumable (e.g. in another thread) - but this copy should be ok to
294+
* resume from.
295+
*/
296+
SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
297+
{
298+
SSL_SESSION *sess = ssl_session_dup_intern(src, ticket);
299+
300+
if (sess != NULL)
301+
sess->not_resumable = 0;
302+
303+
return sess;
304+
}
305+
290306
const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
291307
{
292308
if (len)

ssl/statem/statem_srvr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,9 +2338,8 @@ int tls_construct_server_hello(SSL *s, WPACKET *pkt)
23382338
* so the following won't overwrite an ID that we're supposed
23392339
* to send back.
23402340
*/
2341-
if (s->session->not_resumable ||
2342-
(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)
2343-
&& !s->hit))
2341+
if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)
2342+
&& !s->hit)
23442343
s->session->session_id_length = 0;
23452344

23462345
if (usetls13) {

0 commit comments

Comments
 (0)