~ubuntu-branches/ubuntu/saucy/postgresql-8.4/saucy

« back to all changes in this revision

Viewing changes to src/pl/plperl/plperl_opmask.pl

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-05-15 13:31:46 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100515133146-kd8qmfietgxqvam0
Tags: 8.4.4-1
* Urgency medium due to security fixes.
* New upstream security/bug fix release:
  - Enforce restrictions in plperl using an opmask applied to the whole
    interpreter, instead of using "Safe.pm".
    Recent developments have convinced us that "Safe.pm" is too
    insecure to rely on for making plperl trustable. This change
    removes use of "Safe.pm" altogether, in favor of using a separate
    interpreter with an opcode mask that is always applied. Pleasant
    side effects of the change 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 work as expected in sort routines, and that
    function compilation is significantly faster. (CVE-2010-1169)
  - Prevent PL/Tcl from executing untrustworthy code from pltcl_modules.
    PL/Tcl's feature for autoloading Tcl code from a database table
    could be exploited for trojan-horse attacks, because there was no
    restriction on who could create or insert into that table. This
    change disables the feature unless pltcl_modules is owned by a
    superuser. (However, the permissions on the table are not checked,
    so installations that really need a less-than-secure modules table
    can still grant suitable privileges to trusted non-superusers.)
    Also, prevent loading code into the unrestricted "normal" Tcl
    interpreter unless we are really going to execute a pltclu
    function. (CVE-2010-1170)
  - Fix data corruption during WAL replay of ALTER ... SET TABLESPACE.
    When archive_mode is on, ALTER ... SET TABLESPACE generates a WAL
    record whose replay logic was incorrect. It could write the data to
    the wrong place, leading to possibly-unrecoverable data corruption.
    Data corruption would be observed on standby slaves, and could
    occur on the master as well if a database crash and recovery
    occurred after committing the ALTER and before the next checkpoint.
  - Fix possible crash if a cache reset message is received during
    rebuild of a relcache entry.
    This error was introduced in 8.4.3 while fixing a related failure.
  - Apply per-function GUC settings while running the language
    validator for the function. This avoids failures if the function's code
    is invalid without the setting; an example is that SQL functions may not
    parse if the search_path is not correct.
  - Do constraint exclusion for inherited "UPDATE" and "DELETE" target
    tables when constraint_exclusion = partition.
    Due to an oversight, this setting previously only caused constraint
    exclusion to be checked in "SELECT" commands.
  - Do not allow an unprivileged user to reset superuser-only parameter
    settings.
    Previously, if an unprivileged user ran ALTER USER ... RESET ALL
    for himself, or ALTER DATABASE ... RESET ALL for a database he
    owns, this would remove all special parameter settings for the user
    or database, even ones that are only supposed to be changeable by a
    superuser. Now, the "ALTER" will only remove the parameters that
    the user has permission to change.
  - Avoid possible crash during backend shutdown if shutdown occurs
    when a CONTEXT addition would be made to log entries.
    In some cases the context-printing function would fail because the
    current transaction had already been rolled back when it came time
    to print a log message.
  - Fix erroneous handling of %r parameter in recovery_end_command.
    The value always came out zero.
  - Ensure the archiver process responds to changes in archive_command
    as soon as possible.
  - Fix pl/pgsql's CASE statement to not fail when the case expression
    is a query that returns no rows.
  - Update pl/perl's "ppport.h" for modern Perl versions.
  - Fix assorted memory leaks in pl/python.
  - Handle empty-string connect parameters properly in ecpg.
  - Prevent infinite recursion in psql when expanding a variable that
    refers to itself.
  - Fix psql's \copy to not add spaces around a dot within \copy
    (select ...).
    Addition of spaces around the decimal point in a numeric literal
    would result in a syntax error.
  - Avoid formatting failure in psql when running in a locale context
    that doesn't match the client_encoding.
  - Fix unnecessary "GIN indexes do not support whole-index scans"
    errors for unsatisfiable queries using "contrib/intarray" operators.
  - Ensure that "contrib/pgstattuple" functions respond to cancel
    interrupts promptly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl -w
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use Opcode qw(opset opset_to_ops opdesc full_opset);
 
7
 
 
8
my $plperl_opmask_h   = shift
 
9
        or die "Usage: $0 <output_filename.h>\n";
 
10
 
 
11
my $plperl_opmask_tmp = $plperl_opmask_h."tmp";
 
12
END { unlink $plperl_opmask_tmp }
 
13
 
 
14
open my $fh, ">", "$plperl_opmask_tmp"
 
15
        or die "Could not write to $plperl_opmask_tmp: $!";
 
16
 
 
17
printf $fh "#define PLPERL_SET_OPMASK(opmask) \\\n";
 
18
printf $fh "  memset(opmask, 1, MAXO);\t/* disable all */ \\\n";
 
19
printf $fh "  /* then allow some... */                       \\\n";
 
20
 
 
21
my @allowed_ops = (
 
22
        # basic set of opcodes
 
23
        qw[:default :base_math !:base_io sort time],
 
24
        # require is safe because we redirect the opcode
 
25
        # entereval is safe as the opmask is now permanently set
 
26
        # caller is safe because the entire interpreter is locked down
 
27
        qw[require entereval caller],
 
28
        # These are needed for utf8_heavy.pl:
 
29
        # dofile is safe because we redirect the opcode like require above
 
30
        # print is safe because the only writable filehandles are STDOUT & STDERR
 
31
        # prtf (printf) is safe as it's the same as print + sprintf
 
32
        qw[dofile print prtf],
 
33
        # Disallow these opcodes that are in the :base_orig optag
 
34
        # (included in :default) but aren't considered sufficiently safe
 
35
        qw[!dbmopen !setpgrp !setpriority],
 
36
);
 
37
 
 
38
if (grep { /^custom$/ } opset_to_ops(full_opset) ) {
 
39
        # custom is not deemed a likely security risk as it can't be generated from
 
40
        # perl so would only be seen if the DBA had chosen to load a module that
 
41
        # used it. Even then it's unlikely to be seen because it's typically
 
42
        # generated by compiler plugins that operate after PL_op_mask checks.
 
43
        # But we err on the side of caution and disable it, if it is actually
 
44
        # defined.
 
45
        push(@allowed_ops,qw[!custom]);
 
46
}
 
47
 
 
48
printf $fh "  /* ALLOWED: @allowed_ops */ \\\n";
 
49
 
 
50
foreach my $opname (opset_to_ops(opset(@allowed_ops))) {
 
51
        printf $fh qq{  opmask[OP_%-12s] = 0;\t/* %s */ \\\n},
 
52
                uc($opname), opdesc($opname);
 
53
}
 
54
printf $fh "  /* end */ \n";
 
55
 
 
56
close $fh
 
57
        or die "Error closing $plperl_opmask_tmp: $!";
 
58
 
 
59
rename $plperl_opmask_tmp, $plperl_opmask_h
 
60
        or die "Error renaming $plperl_opmask_tmp to $plperl_opmask_h: $!";
 
61
 
 
62
exit 0;