Skip to content

Commit e9d7083

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 #24043)
1 parent 95b20bb commit e9d7083

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

ssl/ssl_lib.c

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

44584458
/*
44594459
* If the session_id_length is 0, we are not supposed to cache it, and it
4460-
* would be rather hard to do anyway :-)
4460+
* would be rather hard to do anyway :-). Also if the session has already
4461+
* been marked as not_resumable we should not cache it for later reuse.
44614462
*/
4462-
if (s->session->session_id_length == 0)
4463+
if (s->session->session_id_length == 0 || s->session->not_resumable)
44634464
return;
44644465

44654466
/*

ssl/ssl_sess.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,11 @@ SSL_SESSION *SSL_SESSION_new(void)
127127
return ss;
128128
}
129129

130-
SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src)
131-
{
132-
return ssl_session_dup(src, 1);
133-
}
134-
135130
/*
136131
* Create a new SSL_SESSION and duplicate the contents of |src| into it. If
137132
* ticket == 0 then no ticket information is duplicated, otherwise it is.
138133
*/
139-
SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
134+
static SSL_SESSION *ssl_session_dup_intern(const SSL_SESSION *src, int ticket)
140135
{
141136
SSL_SESSION *dest;
142137

@@ -265,6 +260,27 @@ SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
265260
return NULL;
266261
}
267262

263+
SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src)
264+
{
265+
return ssl_session_dup_intern(src, 1);
266+
}
267+
268+
/*
269+
* Used internally when duplicating a session which might be already shared.
270+
* We will have resumed the original session. Subsequently we might have marked
271+
* it as non-resumable (e.g. in another thread) - but this copy should be ok to
272+
* resume from.
273+
*/
274+
SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
275+
{
276+
SSL_SESSION *sess = ssl_session_dup_intern(src, ticket);
277+
278+
if (sess != NULL)
279+
sess->not_resumable = 0;
280+
281+
return sess;
282+
}
283+
268284
const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
269285
{
270286
if (len)

ssl/statem/statem_srvr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,9 +2445,8 @@ CON_FUNC_RETURN tls_construct_server_hello(SSL_CONNECTION *s, WPACKET *pkt)
24452445
* so the following won't overwrite an ID that we're supposed
24462446
* to send back.
24472447
*/
2448-
if (s->session->not_resumable ||
2449-
(!(SSL_CONNECTION_GET_CTX(s)->session_cache_mode & SSL_SESS_CACHE_SERVER)
2450-
&& !s->hit))
2448+
if (!(SSL_CONNECTION_GET_CTX(s)->session_cache_mode & SSL_SESS_CACHE_SERVER)
2449+
&& !s->hit)
24512450
s->session->session_id_length = 0;
24522451

24532452
if (usetls13) {

0 commit comments

Comments
 (0)