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 1wd07J-003oSY-0B for pgpool-hackers@arkaria.postgresql.org; Fri, 26 Jun 2026 06:32:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wd07G-009WCA-33 for pgpool-hackers@arkaria.postgresql.org; Fri, 26 Jun 2026 06:32:42 +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 1wd07G-009WC1-2W for pgpool-hackers@lists.postgresql.org; Fri, 26 Jun 2026 06:32:42 +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 1wd07D-00000000JsN-3b2K for pgpool-hackers@lists.postgresql.org; Fri, 26 Jun 2026 06:32:42 +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:From:Subject:To:Message-Id:Date:Sender:Reply-To:Cc:Content-ID: Content-Description:In-Reply-To:References; bh=CJ0EHfbFTNsCg+iG7ZIg/teuqSw+L8J7cM4ivzz5/D0=; b=4y+Lvuor1aBYkOUBVXsVy4pmA7 Az8yU8XbslE0q7rfcJwhIJHPDYXVaKrdlHHUeiBwMcxvoo4zzmvTkfncRJYgBHoPTl8OgyMPKWdDP UeO6SlxDw9wR3K1DocDGKtDFtXFId5J4D37bVysehzG9q8c8c0HtutIcIV1keg0TawkPAFyqqynw/ Z+/9frng9vQifVA7GhCt66IcYuvo5BAkIh5dAjAgayxR7RdcEXlHX5tr3gLS4BB1ZwcecYufwrOJD NaTUWwPIYz3Wq9EuGydHHhVYe5o04wwK+yjp+zdQFMDR+o1Szoi44hrviS2kJ9EnRtTm8SdZ3YBTa bNKeQIZg==; Received: from [2409:11:4120:300:bfbe:102d:c6f8:4d87] (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 1wd079-006Kn2-32 for pgpool-hackers@lists.postgresql.org; Fri, 26 Jun 2026 06:32:38 +0000 Date: Fri, 26 Jun 2026 15:32:27 +0900 (JST) Message-Id: <20260626.153227.1428186004607098961.ishii@postgresql.org> To: pgpool-hackers@lists.postgresql.org Subject: Reject sub-minimum ErrorResponse length in read_kind_from_backend. From: Tatsuo Ishii X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Fri_Jun_26_15_32_27_2026_961)--" Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:bfbe:102d:c6f8:4d87 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Fri_Jun_26_15_32_27_2026_961)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit 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. Regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp ----Next_Part(Fri_Jun_26_15_32_27_2026_961)-- Content-Type: Text/X-Patch; charset=iso-2022-jp Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="v1-0001-Reject-sub-minimum-ErrorResponse-length-in-read_k.patch"