pgsql: In extensions, don't replace objects not belonging to the extens - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: In extensions, don't replace objects not belonging to the extens
Date
Msg-id E1oL4RI-000szN-TM@gemulon.postgresql.org
Whole thread Raw
List 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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b9b21acc766db54d8c337d508d0fe2f5bf2daab0

Modified Files
--------------
doc/src/sgml/extend.sgml                           |  11 --
src/backend/catalog/pg_collation.c                 |  49 +++++--
src/backend/catalog/pg_depend.c                    |  77 +++++++++--
src/backend/catalog/pg_operator.c                  |   2 +-
src/backend/catalog/pg_type.c                      |   7 +-
src/backend/commands/createas.c                    |  16 ++-
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, 539 insertions(+), 52 deletions(-)


pgsql-committers by date:

Previous
From: Alvaro Herrera
Date:
Subject: pgsql: Translation updates
Next
From: Tom Lane
Date:
Subject: pgsql: Last-minute updates for release notes.