Block ALTER SCHEMA RENAME attack on CREATE EXTENSION etc., via locking.

Commands that run extension SQL scripts intentionally depart from a
standard, "Remove from search_path any schemas that permit untrusted
users to create objects."  While CVE-2020-14350 blocked most attacks,
one remained via ALTER SCHEMA extschema RENAME.  A user with
database-level CREATE privilege could execute arbitrary code as the
bootstrap superuser.  Block that attack by having ALTER SCHEMA RENAME,
CREATE EXTENSION, and ALTER EXTENSION UPDATE lock the schema.  This
makes schema rename locking more like that for object types
AlterObjectRename_internal() covers.

Also, make extension-mutating commands take self-exclusive locks.  Make
relevant commands take the same lock on each dependency extension.  This
doesn't stop a known attack against a specific extension, but
overlapping extension mutations are fragile and not useful.

Back-patch to v14 (all supported versions).

Reported-by: Noah Misch <[email protected]>
Reviewed-by: Greg Burd <[email protected]>
Backpatch-through: 14
Security: CVE-2026-6467

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1dc59af896b76a8311204caf04975ca1c09bc884

Modified Files
--------------
contrib/ltree/.gitignore                        |   2 +
contrib/ltree/Makefile                          |   2 +
contrib/ltree/expected/schema-rename-attack.out |  80 ++++++++++++
contrib/ltree/meson.build                       |   5 +
contrib/ltree/specs/schema-rename-attack.spec   | 127 ++++++++++++++++++
src/backend/commands/extension.c                | 167 ++++++++++++++++++------
src/backend/commands/schemacmds.c               |  20 +--
7 files changed, 355 insertions(+), 48 deletions(-)

Reply via email to