Обсуждение: pgsql: In extensions, don't replace objects not belonging to the extens

Поиск
Список
Период
Сортировка

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

От
Tom Lane
Дата:
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_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5919bb5a5989cda232ac3d1f8b9d90f337be2077

Modified Files
--------------
doc/src/sgml/extend.sgml                           |  11 --
src/backend/catalog/pg_collation.c                 |  46 +++++--
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, 537 insertions(+), 50 deletions(-)