]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MAJOR: h3: prevent demux full BUG_ON() crash with incomplete DATA
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 26 Nov 2026 10:06:00 +0000 (11:06 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 26 Nov 2026 13:43:26 +0000 (14:43 +0100)
Function h3_data_to_htx() transcodes a DATA frame into HTX content. If a
truncated frame is received, content is reduced to the data available in
the buffer. However, the code is murky when only the frame header has
been received but its payload is truncated. Content is set to 0 but the
whole function still executes, which is suboptimal.

Worse, this becomes a major issue if QC_SF_DEM_FULL is set in the same
function call. This violates the invariant on this flag, which must only
be set when there is data to read. This triggers a BUG_ON() crash in
rcv_buf callback, which exists to detect unnecessary wakeups.

This is fixed by adjusting h3_data_to_htx() so that it returns early
when no content is available, preventing unnecessary instructions from
being executed. Most importantly, the HTX output buffer is not checked
anymore so the QC_SF_DEM_FULL flag is not set.

This issue is present since the following patch. Prior to it, empty DATA
frames were totally ignored, but this could prevent FIN reporting, hence
its purpose.

  6c706c1a758b1e8bcdfe0816535edbd5c624db80
  BUG/MEDIUM: h3: do not block FIN on empty DATA frame

Thanks to AndyAnh174 for reporting this issue.

This must be backported up to 2.6.

src/h3.c

index e395c7ff77a04ec39dedd528cff5d8a3c4cfe0ab..3cc5a0b020bc222da63813d6500c5c83270fa492 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -1809,14 +1809,22 @@ static ssize_t h3_data_to_htx(struct qcs *qcs, const struct buffer *buf,
 
        TRACE_ENTER(H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs);
 
-       if (!len && !fin) {
-               /* Ignore empty frame to prevent unnecessary appbuf alloc. Not
-                * performed though if FIN is set as HTX EOM must be reported.
+       if (len > b_data(buf)) {
+               /* Either a truncated frame was received or content is split
+                * across multiple buffers. Only handle the available content.
+                * <len> may be set to zero if only the frame header is there.
                 */
-               TRACE_STATE("skip parsing of empty DATA frame", H3_EV_RX_FRAME, qcs->qcc->conn, qcs);
+               len = b_data(buf);
+               fin = 0;
+       }
+
+       if (!len && !fin) {
+               /* No content to handle, nothing to consume. */
+               TRACE_STATE("no DATA content to consume", H3_EV_RX_FRAME, qcs->qcc->conn, qcs);
                goto out;
        }
 
+       /* Allocation is necessary even if <len> is 0 as FIN must be set in HTX output. */
        if (!(appbuf = qcc_get_stream_rxbuf(qcs))) {
                TRACE_ERROR("data buffer alloc failure", H3_EV_RX_FRAME|H3_EV_RX_DATA, qcs->qcc->conn, qcs);
                goto err;
@@ -1835,11 +1843,6 @@ static ssize_t h3_data_to_htx(struct qcs *qcs, const struct buffer *buf,
                goto out;
        }
 
-       if (len > b_data(buf)) {
-               len = b_data(buf);
-               fin = 0;
-       }
-
        head = b_head(buf);
  retry:
        htx_space = htx_free_data_space(htx);
@@ -1849,6 +1852,7 @@ static ssize_t h3_data_to_htx(struct qcs *qcs, const struct buffer *buf,
        }
 
        if (len > htx_space) {
+               /* Reduce content if not enough space in output buffer. */
                len = htx_space;
                fin = 0;
        }