]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: peers: bound stick-table update messages
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 18 Nov 2026 11:46:10 +0000 (12:46 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Wed, 18 Nov 2026 14:53:46 +0000 (15:53 +0100)
commitef4405d67417f9aac967520122d1fdb597700e15
tree430dd93fdec68f12250d1fb4be4b8e900e36be37
parent62daf6c1e112f708c01a24d3b5474d07b9df82e0
BUG/MEDIUM: peers: bound stick-table update messages

peer_prepare_updatemsg() builds a stick-table update in the <size>-byte
trash buffer but never checked that the encoded data actually fit, and
still carried its "TODO: check size" comment. Fixed-size fields were
copied with memcpy() and every length was encoded with intencode(),
which cannot fail and has no knowledge of the buffer end.

An entry learned from a peer may hold a string key up to key_size - 1,
which the peers protocol accepts in a full-size message. Re-encoding it
adds a 2-byte header, the update identifier and, for timed updates, an
expiration before the key, so the copy runs past the end of the trash
buffer. ASan reports a heap-buffer-overflow WRITE right after the
16384-byte trash region, and on a normal build the two overflowing bytes
land in the next chunk.

Let's check the room left before every copy and every varint encoding.
A new peer_bufcpy() helper copies at most what the buffer can take,
advances the cursor on success and leaves it untouched on failure, so
the success path is unchanged. Lengths are now encoded with
encode_varint(), whose bounds are those of the destination buffer, and
all failures return 0 through a single exit point that releases the
session lock.

The payload length becomes a size_t: as an unsigned short it silently
truncated messages larger than 65535 bytes, which tune.bufsize above 64k
makes reachable.

This should be backported to all supported versions.
src/peers.c