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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7f854a31f7528b869713e53fd484afb19731615e

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                | 149 ++++++++++++++++++------
src/backend/commands/schemacmds.c               |  18 +--
7 files changed, 339 insertions(+), 44 deletions(-)

Reply via email to