pg.ddx.io  pgpool-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Taiki Koshino <koshino@sraoss.co.jp>
To: pgpool-committers@lists.postgresql.org
Subject: pgpool: Add parse_peer_count helper and bound backend_desc array parsin
Date: Tue, 29 Sep 2026 04:43:11 +0000
Message-ID: <E1xBPgN-00000002gHC-2ipQ@gothos.postgresql.org> (raw)

Add parse_peer_count helper and bound backend_desc array parsing.

The wd_json_data.c parsers consume JSON payloads supplied by watchdog
peers (any TCP host that can reach wd_port; auth defeated by the
default-empty wd_authkey) and write the parsed contents into
fixed-size arrays inside palloc'd POOL_CONFIG / BackendDesc /
WdNodeInfo storage. get_pool_config_from_json() in particular copied
value->u.array.length verbatim into config->backend_desc->num_backends
without any upper bound, so a peer-supplied "backend_desc" array of
more than MAX_NUM_BACKENDS (128) entries drove the loop past the
embedded BackendInfo backend_info[MAX_NUM_BACKENDS] array, writing
attacker-controlled port and hostname bytes into adjacent heap. The
sibling parser get_pg_backend_node_status_from_json() already clamps
the same way, so this is a per-handler omission, not a structural
limit; sibling wd_nodes parsing in the same function has the same
bug and will be migrated in a follow-up patch.

Introduce a static helper

    static int
    parse_peer_count(const json_value *jv, const char *field,
                     int max_count);

that validates the value is a JSON array, reads its length, and
rejects with ereport(ERROR, ...) when the count is negative or
exceeds the caller-supplied bound. The longjmp out of the parser
matches the existing exit channel for json_get_*_value_for_key on
malformed input, so callers do not need new error-path handling.

Migrate the backend_desc loop in get_pool_config_from_json() to use
the helper, capped at MAX_NUM_BACKENDS. Replace the per-element
strncpy(... sizeof(field) - 1) with strlcpy(... sizeof(field)) so
the destination is guaranteed NUL-terminated when the peer-supplied
hostname is exactly MAX_DB_HOST_NAMELEN (254) bytes.

Reported-by: Emond Papegaaij <emond.papegaaij@topicus.nl>
Reported-by: Claude
Author: Bo Peng <pengbo@sraoss.co.jp>
CVE-2026-92869
Backpatch-through: v4.3

Branch
------
V4_6_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=8fbd5ee1656cbf48e195728e1d04b8ac08002...

Modified Files
--------------
src/watchdog/wd_json_data.c | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1xBPgN-00000002gHC-2ipQ@gothos.postgresql.org>
Permalink:  ../E1xBPgN-00000002gHC-2ipQ@gothos.postgresql.org/
Also on:    postgresql.org/message-id/E1xBPgN-00000002gHC-2ipQ@gothos.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgpool-committers@postgresql.org
  Cc: koshino@sraoss.co.jp
  Subject: Re: pgpool: Add parse_peer_count helper and bound backend_desc array parsin
  In-Reply-To: <E1xBPgN-00000002gHC-2ipQ@gothos.postgresql.org>
  References: <E1xBPgN-00000002gHC-2ipQ@gothos.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox