Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whE91-0005dn-0A for pgpool-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 22:19:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whE8z-002zlq-1x for pgpool-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 22:19:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whE8z-002zli-1Q for pgpool-hackers@lists.postgresql.org; Tue, 07 Jul 2026 22:19:58 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1whE8w-00000000792-2fAU for pgpool-hackers@lists.postgresql.org; Tue, 07 Jul 2026 22:19:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=r2+yubEmdZbAUnrxyqf0bYIxvdR86HcYddxQpY4J8lU=; b=6xYVg846WpCvsrgHhEs4bfyrJG IPjzkCCKYEizUnD1AuZwc0stzEuLf3zSfICBjIwfC4XjiGSXd533LIAqgoVyojfHjNPWj9AEiMUW7 F2QHYKHgAhMl/njw73VBLtg7emWv/v34s8tur1tlH7zfvepGRZjKdWuslRS5sLxG1oU9qTwUF1XtP TrucTzz7jab5FFKh/b/0bBTGep9ufTjQobla3GyBHKIvDuaE7UoetAdotXRBlXDpBILGYpPxlb70K eyHMNUWVolPxgBPUUra3eDNAn7S5cbTNT1V2gd/AqCd3W2afgv/8xXONvAFDxpatWLLfC/qIYH7xc M+2sqLRA==; Received: from [2409:11:4120:300:7e22:7ac9:561b:b2f6] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whE8t-000WTG-2Q; Tue, 07 Jul 2026 22:19:55 +0000 Date: Wed, 08 Jul 2026 07:19:42 +0900 (JST) Message-Id: <20260708.071942.395809594067831785.ishii@postgresql.org> To: pgpool-hackers@lists.postgresql.org Cc: Emond Papegaaij Subject: Re: Reject sub-minimum ErrorResponse length in read_kind_from_backend. From: Tatsuo Ishii In-Reply-To: <20260626.153227.1428186004607098961.ishii@postgresql.org> References: <20260626.153227.1428186004607098961.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:7e22:7ac9:561b:b2f6 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Emond Papegaaij reported a bug 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 ― i.e. in {0,1,2,3} ― 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 ― > 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. > > Patch attached. Peng and Koshino reviewed the patch off-list and they agreed that it looks good. I have pushed the patch to all supported branches. Thank you, Emond. https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=912d7ce0b9d3a29a343a4b828e86fc05c0f47755 -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp