pgsql: Further harden PL/Perl against tied-scalar mischief.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Further harden PL/Perl against tied-scalar mischief.
Date: 2026-11-09 14:21:52
Message-ID: E1xQQFs-000000003QK-3Amq@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Further harden PL/Perl against tied-scalar mischief.

PL/Perl decides whether Perl threw an error by testing SvTRUE(ERRSV).
If the thrown value is an object whose class overloads "bool", that
runs user-supplied Perl code. There is no eval{} in scope at some of
these tests, so if that code throws in turn, Perl writes the message
to stderr and exits the backend, not the behavior we want.

To fix, don't ask Perl at all in the case that matters. Any reference
is true regardless of what its class claims, so a thrown object is an
error by definition, while overloading cannot apply to a non-reference.
Add errsv_is_true() to encapsulate that and replace tests of ERRSV
with that.

Also, consider the possibility that trying to stringify ERRSV throws
an error, which can also be arranged with a hostile object definition.
That risks an infinite loop in PG_PERL_TRY, so install code to prevent
repeating such a loop.

Lastly, stringify ERRSV outside our ereport() calls not inside. If we
do it inside then a thrown Perl error temporarily leaks an errordata[]
slot for the unfinished ereport. While it's not clear that this makes
it possible to overrun ERRORDATA_STACK_SIZE, it seems best to avoid
the leak.

Reported-by: Dwij Mehta <dwijimehta(at)gmail(dot)com>
Author: Andrew Dunstan <andrew(at)dunslane(dot)net>
Co-authored-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Backpatch-through: 14
Security: CVE-2026-116326

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/80e73b3ce5d4ad68406d87480fd227cb6a5994a8
Author: Andrew Dunstan <andrew(at)dunslane(dot)net>

Modified Files
--------------
src/pl/plperl/plperl.c | 81 +++++++++++++++++++++++++++++++++++++-------------
src/pl/plperl/plperl.h | 65 +++++++++++++++++++++++++++++++++-------
2 files changed, 116 insertions(+), 30 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:21:53 pgsql: Reject extnamespace if it's temporary or it's '$user'::regnamesp
Previous Message Noah Misch 2026-11-09 14:21:51 pgsql: Close portals at end of trigger functions with transition tables