pgsql: In extensions, don't replace objects not belonging to the extens

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: In extensions, don't replace objects not belonging to the extens
Date: 2022-08-08 15:13:08
Message-ID: E1oL4RI-000szX-VC@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

In extensions, don't replace objects not belonging to the extension.

Previously, if an extension script did CREATE OR REPLACE and there was
an existing object not belonging to the extension, it would overwrite
the object and adopt it into the extension. This is problematic, first
because the overwrite is probably unintentional, and second because we
didn't change the object's ownership. Thus a hostile user could create
an object in advance of an expected CREATE EXTENSION command, and would
then have ownership rights on an extension object, which could be
modified for trojan-horse-type attacks.

Hence, forbid CREATE OR REPLACE of an existing object unless it already
belongs to the extension. (Note that we've always forbidden replacing
an object that belongs to some other extension; only the behavior for
previously-free-standing objects changes here.)

For the same reason, also fail CREATE IF NOT EXISTS when there is
an existing object that doesn't belong to the extension.

Our thanks to Sven Klemm for reporting this problem.

Security: CVE-2022-2625

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5579726bd60a6e7afb04a3548bced348cd5ffd89

Modified Files
--------------
doc/src/sgml/extend.sgml | 11 --
src/backend/catalog/pg_collation.c | 49 +++++--
src/backend/catalog/pg_depend.c | 74 +++++++++-
src/backend/catalog/pg_operator.c | 2 +-
src/backend/catalog/pg_type.c | 7 +-
src/backend/commands/createas.c | 18 ++-
src/backend/commands/foreigncmds.c | 19 ++-
src/backend/commands/schemacmds.c | 25 +++-
src/backend/commands/sequence.c | 8 ++
src/backend/commands/statscmds.c | 4 +
src/backend/commands/view.c | 16 ++-
src/backend/parser/parse_utilcmd.c | 10 ++
src/include/catalog/dependency.h | 2 +
src/test/modules/test_extensions/Makefile | 5 +-
.../test_extensions/expected/test_extensions.out | 153 +++++++++++++++++++++
.../test_extensions/sql/test_extensions.sql | 110 +++++++++++++++
.../test_extensions/test_ext_cine--1.0--1.1.sql | 26 ++++
.../modules/test_extensions/test_ext_cine--1.0.sql | 25 ++++
.../modules/test_extensions/test_ext_cine.control | 3 +
.../modules/test_extensions/test_ext_cor--1.0.sql | 20 +++
.../modules/test_extensions/test_ext_cor.control | 3 +
21 files changed, 540 insertions(+), 50 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2022-08-08 15:29:00 pgsql: Last-minute updates for release notes.
Previous Message Alvaro Herrera 2022-08-08 10:42:10 pgsql: Translation updates