]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server/ssl: clear the shared good session index on failure
authorWilly Tarreau <w@1wt.eu>
Mon, 21 Aug 2023 10:04:01 +0000 (12:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 31 Aug 2023 06:50:01 +0000 (08:50 +0200)
If we fail to set the session using SSL_set_session(), we want to quickly
erase our index from the shared one so that any other thread with a valid
session replaces it.

src/ssl_sock.c

index 679ae2e780908e390e740a63a4da51042ebb9eae..90bc7be91fc685ddb023997daa39b5351a7e7430 100644 (file)
@@ -5752,6 +5752,9 @@ static int ssl_sock_init(struct connection *conn, void **xprt_ctx)
                        SSL_SESSION *sess = d2i_SSL_SESSION(NULL, &ptr, srv->ssl_ctx.reused_sess[tid].size);
 
                        if (sess && !SSL_set_session(ctx->ssl, sess)) {
+                               uint old_tid = HA_ATOMIC_LOAD(&srv->ssl_ctx.last_ssl_sess_tid); // 0=none, >0 = tid + 1
+                               if (old_tid == tid + 1)
+                                       HA_ATOMIC_CAS(&srv->ssl_ctx.last_ssl_sess_tid, &old_tid, 0); // no more valid
                                SSL_SESSION_free(sess);
                                HA_RWLOCK_WRLOCK(SSL_SERVER_LOCK, &srv->ssl_ctx.reused_sess[tid].sess_lock);
                                ha_free(&srv->ssl_ctx.reused_sess[tid].ptr);