]> git.ipfire.org Git - thirdparty/postgresql.git/commit
In extensions, don't replace objects not belonging to the extension.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 8 Aug 2022 15:12:31 +0000 (11:12 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 8 Aug 2022 15:12:31 +0000 (11:12 -0400)
commit5919bb5a5989cda232ac3d1f8b9d90f337be2077
tree053383a7a728fbf7265e5ac5f4e445424e72a72e
parent415af1a4d88a83c93d6277bb8593d468909a0752
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]