| From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
|---|---|
| To: | pgpool-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgpool: Reject sub-minimum ErrorResponse length in read_kind_from_backe |
| Date: | 2026-07-07 22:14:04 |
| Message-ID: | E1whE3I-00GC87-2L@gothos.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgpool-committers |
Reject sub-minimum ErrorResponse length in read_kind_from_backend.
read_kind_from_backend() handles a backend ErrorResponse on the V3
path by reading the 4-byte length field, palloc'ing a buffer sized at
ntohl(len), and immediately memcpy()ing all 4 bytes of the
network-order length back into that buffer. When a backend (malicious,
buggy, or speaking a non-V3 dialect that has slipped past earlier
checks) sends a length below 4 $B!=(B i.e. in {0,1,2,3} $B!=(B the palloc
chunk is smaller than sizeof(len) and the memcpy overruns the heap
allocation. The follow-up `len -= 4` then underflows to a huge
unsigned value, which the subsequent `repalloc(unread_p, sizeof(len) +
len)` may wrap, and pool_read2() is asked for a colossal payload $B!=(B
all on top of an already-corrupted heap.
Reject any ntohl(len) below sizeof(len) up front with ereport(ERROR,
...). The error path is the existing longjmp-based one used by every
other malformed-input check in this function, so the connection is
torn down cleanly without touching unread_p.
Reported-by: Emond Papegaaij <emond(dot)papegaaij(at)gmail(dot)com>
Reported-by: Claude code
Author: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Reviewed-by: Bo Peng <pengbo(at)sraoss(dot)co(dot)jp>
Reviewed-by: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
Discussion: https://www.postgresql.org/message-id/20260626.153227.1428186004607098961.ishii%40postgresql.org
Backpatch-through: v4.3
Branch
------
V4_5_STABLE
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=9e84817fb572c11b954be60a0bdf9cde911cdbb7
Modified Files
--------------
src/protocol/pool_process_query.c | 4 ++++
1 file changed, 4 insertions(+)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2026-07-07 22:14:10 | pgpool: Reject sub-minimum ErrorResponse length in read_kind_from_backe |
| Previous Message | Tatsuo Ishii | 2026-07-07 22:13:59 | pgpool: Reject sub-minimum ErrorResponse length in read_kind_from_backe |