Skip to content

Commit

Permalink
Fix data race between SSL_SESSION_list_add and ssl_session_dup
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
(Merged from openssl#24673)
  • Loading branch information
rschu1ze committed Jun 21, 2024
1 parent e3eca22 commit 5d81fa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 7 additions & 6 deletions ssl/ssl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ struct ssl_session_st {
* certificate is not ok, we must remember the error for session reuse:
*/
long verify_result; /* only for servers */
CRYPTO_REF_COUNT references;
OSSL_TIME timeout;
OSSL_TIME time;
OSSL_TIME calc_timeout;
Expand All @@ -542,11 +541,6 @@ struct ssl_session_st {
* load the 'cipher' structure */
unsigned int kex_group; /* TLS group from key exchange */
CRYPTO_EX_DATA ex_data; /* application specific data */
/*
* These are used to make removal of session-ids more efficient and to
* implement a maximum cache size.
*/
struct ssl_session_st *prev, *next;

struct {
char *hostname;
Expand Down Expand Up @@ -576,6 +570,13 @@ struct ssl_session_st {
size_t ticket_appdata_len;
uint32_t flags;
SSL_CTX *owner;

/*
* These are used to make removal of session-ids more efficient and to
* implement a maximum cache size. Access requires protection of ctx->lock.
*/
struct ssl_session_st *prev, *next;
CRYPTO_REF_COUNT references;
};

/* Extended master secret support */
Expand Down
7 changes: 6 additions & 1 deletion ssl/ssl_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
dest = OPENSSL_malloc(sizeof(*dest));
if (dest == NULL)
return NULL;
memcpy(dest, src, sizeof(*dest));

/*
* src is logically read-only but the prev/next pointers are not, they are
* part of the session cache and can be modified concurrently.
*/
memcpy(dest, src, offsetof(SSL_SESSION, prev));

/*
* Set the various pointers to NULL so that we can call SSL_SESSION_free in
Expand Down

0 comments on commit 5d81fa7

Please sign in to comment.