Block environment variable mutations from trusted PL/Perl.
authorNoah Misch <noah@leadboat.com>
Mon, 11 Nov 2024 14:23:43 +0000 (06:23 -0800)
committerNoah Misch <noah@leadboat.com>
Mon, 11 Nov 2024 14:23:47 +0000 (06:23 -0800)
commite530835c6cc5b2dbf330ebe6b0a7fb9f19f5a54c
treec86ddefcdd623c8c1ae3bb85995a8e5b38aa0bd5
parent3f2c24e55b7ecfd06a4b65b9a52f74f27b580046
Block environment variable mutations from trusted PL/Perl.

Many process environment variables (e.g. PATH), bypass the containment
expected of a trusted PL.  Hence, trusted PLs must not offer features
that achieve setenv().  Otherwise, an attacker having USAGE privilege on
the language often can achieve arbitrary code execution, even if the
attacker lacks a database server operating system user.

To fix PL/Perl, replace trusted PL/Perl %ENV with a tied hash that just
replaces each modification attempt with a warning.  Sites that reach
these warnings should evaluate the application-specific implications of
proceeding without the environment modification:

  Can the application reasonably proceed without the modification?

    If no, switch to plperlu or another approach.

    If yes, the application should change the code to stop attempting
    environment modifications.  If that's too difficult, add "untie
    %main::ENV" in any code executed before the warning.  For example,
    one might add it to the start of the affected function or even to
    the plperl.on_plperl_init setting.

In passing, link to Perl's guidance about the Perl features behind the
security posture of PL/Perl.

Back-patch to v12 (all supported versions).

Andrew Dunstan and Noah Misch

Security: CVE-2024-10979
doc/src/sgml/plperl.sgml
src/pl/plperl/GNUmakefile
src/pl/plperl/expected/plperl_env.out [new file with mode: 0644]
src/pl/plperl/plc_trusted.pl
src/pl/plperl/sql/plperl_env.sql [new file with mode: 0644]
src/test/regress/regress.c