From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Avoid using unsafe search_path settings during dump and restore.
Date: Mon, 26 Feb 2018 15:20:02 +0000
Message-ID: <E1eqKZO-0005dx-54@gemulon.postgresql.org> (raw)
Avoid using unsafe search_path settings during dump and restore.
Historically, pg_dump has "set search_path = foo, pg_catalog" when
dumping an object in schema "foo", and has also caused that setting
to be used while restoring the object. This is problematic because
functions and operators in schema "foo" could capture references meant
to refer to pg_catalog entries, both in the queries issued by pg_dump
and those issued during the subsequent restore run. That could
result in dump/restore misbehavior, or in privilege escalation if a
nefarious user installs trojan-horse functions or operators.
This patch changes pg_dump so that it does not change the search_path
dynamically. The emitted restore script sets the search_path to what
was used at dump time, and then leaves it alone thereafter. Created
objects are placed in the correct schema, regardless of the active
search_path, by dint of schema-qualifying their names in the CREATE
commands, as well as in subsequent ALTER and ALTER-like commands.
Since this change requires a change in the behavior of pg_restore
when processing an archive file made according to this new convention,
bump the archive file version number; old versions of pg_restore will
therefore refuse to process files made with new versions of pg_dump.
Security: CVE-2018-1058
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/b8a2908f0ac735da68d49be2bce2d523e363f67b
Modified Files
--------------
src/backend/utils/adt/ruleutils.c | 48 +-
src/bin/pg_dump/dumputils.c | 100 +-
src/bin/pg_dump/dumputils.h | 6 +-
src/bin/pg_dump/pg_backup.h | 3 +
src/bin/pg_dump/pg_backup_archiver.c | 53 +-
src/bin/pg_dump/pg_backup_archiver.h | 4 +-
src/bin/pg_dump/pg_dump.c | 1726 +++++++++-------------
src/bin/pg_dump/pg_dumpall.c | 36 +-
src/bin/pg_dump/t/002_pg_dump.pl | 376 ++---
src/test/modules/test_pg_dump/t/001_base.pl | 50 +-
src/test/regress/expected/collate.icu.utf8.out | 12 +-
src/test/regress/expected/collate.linux.utf8.out | 12 +-
src/test/regress/expected/collate.out | 12 +-
src/test/regress/expected/rules.out | 78 +-
src/test/regress/expected/triggers.out | 12 +-
15 files changed, 1113 insertions(+), 1415 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Avoid using unsafe search_path settings during dump and restore.
In-Reply-To: <E1eqKZO-0005dx-54@gemulon.postgresql.org>
References: <E1eqKZO-0005dx-54@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox