]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: quic: protect the ChaCha20 header protection context from being freed
authorFrederic Lecaille <flecaille@haproxy.com>
Tue, 1 Sep 2026 07:52:01 +0000 (09:52 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Wed, 2 Sep 2026 13:32:32 +0000 (15:32 +0200)
quic_tls_secrets_keys_free() calls EVP_CIPHER_CTX_free() on <hp_ctx> without
checking it against EVP_CIPHER_CTX_CHACHA20. With AWS-LC this member may hold
this value, which points to a static object and not to an allocated context.
quic_tls_ctx_secs_free() already guards against it.

This cannot happen today, as the only caller runs before the contexts are
created. Add the same guard, and reset <hp_ctx> and <ctx> so that calling this
function twice is harmless.

Should be backported as far as 2.6 to ease any future bug fix backport.

include/haproxy/quic_tls.h

index 0ee2eb40e8b79a26d93585a6ddff3ec8dd0c72ce..dac45a3f297a1baa91bf17f7a7e7000cc5db0849 100644 (file)
@@ -868,9 +868,16 @@ static inline void quic_tls_secrets_keys_free(struct quic_tls_secrets *secs)
        }
 
        /* HP protection */
+#ifdef QUIC_AEAD_API
+       if (secs->hp_ctx != EVP_CIPHER_CTX_CHACHA20)
+               EVP_CIPHER_CTX_free(secs->hp_ctx);
+#else
        EVP_CIPHER_CTX_free(secs->hp_ctx);
+#endif
+       secs->hp_ctx = NULL;
        /* AEAD decryption */
        QUIC_AEAD_CTX_free(secs->ctx);
+       secs->ctx = NULL;
        pool_free(pool_head_quic_tls_iv,  secs->iv);
        pool_free(pool_head_quic_tls_key, secs->key);