]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: ssl: trim dropped kTLS records from the end of the buffer
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 24 Nov 2026 17:33:04 +0000 (18:33 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 25 Nov 2026 14:04:54 +0000 (15:04 +0100)
With AWS-LC and kTLS, ssl_sock_to_buf() reads the records itself, and
drops the NewSessionTicket and close_notify ones it has just received
using b_del(). But this removes data from the head of the buffer, while
the record was appended at its tail. When the buffer already contains
data, their beginning is lost and the record stays in the buffer,
resulting in a corrupted stream, typically an invalid HTTP response
when a server sends a close_notify right after its response. This
rarely shows up for now, because a kTLS read is almost always the last
one of a call.

Let's use b_sub() to remove the record from the tail.

This was introduced in 3.3-dev7 by commit 5da354098 ("MEDIUM: ssl:
Handle non-Application data record with AWS-LC"). It must be backported
to 3.3.

src/ssl_sock.c

index 048d61c884bf913aa8019aaf1e1dc9649d0c3f5d..34b646f9f982295660a7ef159b7be7883bf74602 100644 (file)
@@ -7714,7 +7714,7 @@ static size_t ssl_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
                                                /*
                                                 * Just ignore new session tickets
                                                 */
-                                               b_del(buf, ret);
+                                               b_sub(buf, ret);
                                                continue;
 
                                        } else if (record_type != SSL3_RT_APPLICATION_DATA) {
@@ -7724,7 +7724,7 @@ static size_t ssl_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
                                                 */
                                                if (record_type == SSL3_RT_ALERT && ret == 2 &&
                                                    tmpbuf[0] == SSL_TLSEXT_ERR_ALERT_WARNING && tmpbuf[1] == SSL_AD_CLOSE_NOTIFY) {
-                                                       b_del(buf, ret);
+                                                       b_sub(buf, ret);
                                                        goto read0;
                                                } else {
                                                        conn->err_code = CO_ER_SSL_FATAL;