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.
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;
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);
}
if (len > htx_space) {
+ /* Reduce content if not enough space in output buffer. */
len = htx_space;
fin = 0;
}