In extensions, don't replace objects not belonging to the extension.
authorTom Lane <[email protected]>
Mon, 8 Aug 2022 15:12:31 +0000 (11:12 -0400)
committerTom Lane <[email protected]>
Mon, 8 Aug 2022 15:12:31 +0000 (11:12 -0400)
commit7e92f78abe80e4b30e648a40073abb59057e21f8
tree7baceac492e02a01407855ddb426fb3b3e17a1dc
parent330c48b28470ce423769b95e18a65e20d7d8a9b8
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
21 files changed:
doc/src/sgml/extend.sgml
src/backend/catalog/pg_collation.c
src/backend/catalog/pg_depend.c
src/backend/catalog/pg_operator.c
src/backend/catalog/pg_type.c
src/backend/commands/createas.c
src/backend/commands/foreigncmds.c
src/backend/commands/schemacmds.c
src/backend/commands/sequence.c
src/backend/commands/statscmds.c
src/backend/commands/view.c
src/backend/parser/parse_utilcmd.c
src/include/catalog/dependency.h
src/test/modules/test_extensions/Makefile
src/test/modules/test_extensions/expected/test_extensions.out
src/test/modules/test_extensions/sql/test_extensions.sql
src/test/modules/test_extensions/test_ext_cine--1.0--1.1.sql [new file with mode: 0644]
src/test/modules/test_extensions/test_ext_cine--1.0.sql [new file with mode: 0644]
src/test/modules/test_extensions/test_ext_cine.control [new file with mode: 0644]
src/test/modules/test_extensions/test_ext_cor--1.0.sql [new file with mode: 0644]
src/test/modules/test_extensions/test_ext_cor.control [new file with mode: 0644]