Skip to content

Commit 60028fd

Browse files
committed
Abandon the use of Perl's Safe.pm to enforce restrictions in plperl, as it is
fundamentally insecure. Instead apply an opmask to the whole interpreter that imposes restrictions on unsafe operations. These restrictions are much harder to subvert than is Safe.pm, since there is no container to be broken out of. Backported to release 7.4. In releases 7.4, 8.0 and 8.1 this also includes the necessary backporting of the two interpreters model for plperl and plperlu adopted in release 8.2. In versions 8.0 and up, the use of Perl's POSIX module to undo its locale mangling on Windows has become insecure with these changes, so it is replaced by our own routine, which is also faster. Nice side effects of the changes include that it is now possible to use perl's "strict" pragma in a natural way in plperl, and that perl's $a and $b variables now work as expected in sort routines, and that function compilation is significantly faster. Tim Bunce and Andrew Dunstan, with reviews from Alex Hunsaker and Alexey Klyukin. Security: CVE-2010-1169
1 parent e274064 commit 60028fd

File tree

4 files changed

+493
-78
lines changed

4 files changed

+493
-78
lines changed

doc/src/sgml/plperl.sgml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/plperl.sgml,v 2.20 2003/08/31 17:32:19 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/plperl.sgml,v 2.20.2.1 2010/05/13 16:44:35 adunstan Exp $
33
-->
44

55
<chapter id="plperl">
@@ -259,7 +259,26 @@ CREATE FUNCTION badfunc() RETURNS integer AS '
259259
If the above function was created by a superuser using the language
260260
<literal>plperlu</>, execution would succeed.
261261
</para>
262-
</sect1>
262+
263+
<note>
264+
<para>
265+
For security reasons, to stop a leak of privileged operations from
266+
<application>PL/PerlU</> to <application>PL/Perl</>, these two languages
267+
have to run in separate instances of the Perl interpreter. If your
268+
Perl installation has been appropriately compiled, this is not a problem.
269+
However, not all installations are compiled with the requisite flags.
270+
If <productname>PostgreSQL</> detects that this is the case then it will
271+
not start a second interpreter, but instead create an error. In
272+
consequence, in such an installation, you cannot use both
273+
<application>PL/PerlU</> and <application>PL/Perl</> in the same backend
274+
process. The remedy for this is to obtain a Perl installation created
275+
with the appropriate flags, namely either <literal>usemultiplicity</> or
276+
both <literal>usethreads</> and <literal>useithreads</>.
277+
For more details,see the <literal>perlembed</> manual page.
278+
</para>
279+
</note>
280+
281+
</sect1>
263282

264283
<sect1 id="plperl-missing">
265284
<title>Missing Features</title>

src/pl/plperl/GNUmakefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for PL/Perl
2-
# $Header: /cvsroot/pgsql/src/pl/plperl/GNUmakefile,v 1.10.6.1 2004/01/21 19:25:11 tgl Exp $
2+
# $Header: /cvsroot/pgsql/src/pl/plperl/GNUmakefile,v 1.10.6.2 2010/05/13 16:44:35 adunstan Exp $
33

44
subdir = src/pl/plperl
55
top_builddir = ../../..
@@ -18,7 +18,7 @@ ifeq ($(GCC),yes)
1818
override CFLAGS := $(filter-out -Wall -Wmissing-declarations -Wmissing-prototypes, $(CFLAGS))
1919
endif
2020

21-
override CPPFLAGS := -I$(srcdir) -I$(perl_archlibexp)/CORE $(CPPFLAGS)
21+
override CPPFLAGS := -I. -I$(srcdir) -I$(perl_archlibexp)/CORE $(CPPFLAGS)
2222

2323

2424
NAME = plperl
@@ -33,6 +33,13 @@ include $(top_srcdir)/src/Makefile.shlib
3333

3434
all: all-lib
3535

36+
plperl.o: plperl_opmask.h
37+
38+
plperl_opmask.h: plperl_opmask.pl
39+
$(PERL) $< $@
40+
41+
42+
3643
SPI.c: SPI.xs
3744
$(PERL) $(perl_privlibexp)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
3845

@@ -52,7 +59,7 @@ uninstall:
5259
rm -f $(DESTDIR)$(pkglibdir)/plperl$(DLSUFFIX)
5360

5461
clean distclean maintainer-clean: clean-lib
55-
rm -f SPI.c $(OBJS)
62+
rm -f SPI.c $(OBJS) plperl_opmask.h
5663

5764
else # can't build
5865

0 commit comments

Comments
 (0)