]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: htx: Reserve a block descriptor for zero-sized blocks
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Sep 2026 16:11:43 +0000 (18:11 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 15 Sep 2026 05:38:41 +0000 (07:38 +0200)
commitba2b10ab2134c14e5d9d64671528d3c2900a5ea5
tree297afe7d5f55c47252f01e52e276b6690e74353e
parent217da687210699153f6569813c340e5131005807
BUG/MEDIUM: htx: Reserve a block descriptor for zero-sized blocks

htx_reserve_nxblk() only refused to reserve a new block when
<blksz> was greater than the free space available for the payload, as
reported by htx_free_data_space(). However this function returns 0 in two
different cases: when there is exactly enough room left for a block
descriptor and no payload, but also when there is not even enough room for
a block descriptor. Both cases cannot be distinguished when a zero-sized
block is added, because the test is then always false.

In that case, the function goes on and hands out a block descriptor that
does not fit in the blocks table. Concretely, with <head> set to 0 and less
than sizeof(struct htx_blk) bytes left in the message, the defragmentation
has nothing to reclaim and the descriptor is placed inside the payload
part, silently overwriting the end of the last block. In addition, the tail
is incremented, so htx_used_space() becomes greater than the message size
and htx_free_space() wraps around to a huge value. None of the sanity
checks at the end of the function is able to detect it.

The free space is now explicitly tested against the size of a block
descriptor. This way, a zero-sized block is refused when there is no room
left for its descriptor. It is fixed in htx_reserve_nxblk() to also cover
htx_add_data_atonce(), which has the same flaw in its own test, and
htx_add_header()/htx_add_trailer(), which compute a null size when both the
name and the value are empty.

The only known caller able to request a zero-sized block is the
decompression filter, when there is no room left to drain the decompressed
data. It was introduced in 3.5-dev, so no released version should be
affected. However the flaw exists in the HTX API since its introduction in
1.9, so this patch may be backported as hardening to all stable versions.

Reported-by: Asjid Kalam <asjid.kalam@gmail.com>
src/htx.c