]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: ssl: cleanse TLS ticket keys before freeing
authorWilliam Lallemand <wlallemand@irq6.net>
Fri, 25 Sep 2026 08:01:03 +0000 (08:01 +0000)
committerWilliam Lallemand <wlallemand@irq6.net>
Fri, 25 Sep 2026 08:45:00 +0000 (10:45 +0200)
Cleanse tlskeys with ha_memset_s() before freeing.

tlskeys contains tls_sess_key structures holding encryption keys for
session resumption. Leaving these secrets in freed heap memory risks
exposure through core dumps or memory disclosure bugs.

This patch cleanses intermediate buffers used to parse the tlskeys as
well.

This fixes issue #3504.

src/cfgparse-ssl.c
src/ssl_sock.c

index 08a9ade9e64cba3e241a3392e1541bf6448cd069..d9d213b70893c4f38feecdf49bf4a0651ccf088c 100644 (file)
@@ -1551,6 +1551,7 @@ static int bind_parse_tls_ticket_keys(char **args, int cur_arg, struct proxy *px
                        thisline[--len] = 0;
 
                dec_size = base64dec(thisline, len, (char *) (keys_ref->tlskeys + i % TLS_TICKETS_NO), sizeof(union tls_sess_key));
+               ha_memset_s(thisline, 0, sizeof(thisline));
                if (dec_size < 0) {
                        memprintf(err, "'%s' : unable to decode base64 key on line %d", args[cur_arg+1], i + 1);
                        goto fail;
@@ -1590,11 +1591,16 @@ static int bind_parse_tls_ticket_keys(char **args, int cur_arg, struct proxy *px
        return 0;
 
   fail:
+       ha_memset_s(thisline, 0, sizeof(thisline));
        if (f)
                fclose(f);
        if (keys_ref) {
                free(keys_ref->filename);
-               free(keys_ref->tlskeys);
+               if (keys_ref->tlskeys) {
+                       ha_memset_s(keys_ref->tlskeys, 0,
+                                   sizeof(*keys_ref->tlskeys) * TLS_TICKETS_NO);
+                       free(keys_ref->tlskeys);
+               }
                free(keys_ref);
        }
        return ERR_ALERT | ERR_FATAL;
index 1f971d717e7e1eece1679a0a24dc1636673302bc..c216b70cc8099edb3bf9d7d9657e9c38f3cf07f6 100644 (file)
@@ -6026,7 +6026,11 @@ void ssl_sock_destroy_bind_conf(struct bind_conf *bind_conf)
        free(bind_conf->ca_sign_pass);
        if (bind_conf->keys_ref && !--bind_conf->keys_ref->refcount) {
                free(bind_conf->keys_ref->filename);
-               free(bind_conf->keys_ref->tlskeys);
+               if (bind_conf->keys_ref->tlskeys) {
+                       ha_memset_s(bind_conf->keys_ref->tlskeys, 0,
+                                   sizeof(*bind_conf->keys_ref->tlskeys) * TLS_TICKETS_NO);
+                       free(bind_conf->keys_ref->tlskeys);
+               }
                LIST_DELETE(&bind_conf->keys_ref->list);
                free(bind_conf->keys_ref);
        }
@@ -8608,7 +8612,10 @@ static int cli_parse_set_tlskeys(char **args, char *payload, struct appctx *appc
                return cli_err(appctx, "'set ssl tls-key' received invalid base64 encoded TLS key.\n");
 
        trash.data = ret;
-       if (ssl_sock_update_tlskey_ref(ref, &trash) < 0)
+       ret = ssl_sock_update_tlskey_ref(ref, &trash);
+       ha_memset_s(trash.area, 0, trash.data);
+       chunk_reset(&trash);
+       if (ret < 0)
                return cli_err(appctx, "'set ssl tls-key' received a key of wrong size.\n");
 
        return cli_msg(appctx, LOG_INFO, "TLS ticket key updated!\n");