Repository navigation
Harden extension script execution and custom-type creation - #326
Open
sibowu-aws wants to merge 1 commit into
Open
sibowu-aws wants to merge 1 commit into
sibowu-aws wants to merge 1 commit into
Conversation
sibowu-aws
force-pushed
the
cve-2026-extension-script-hardening
branch
from
November 19, 2026 18:06
137b310 to
d6ad576
Compare
…0153, -116316) pg_tle forks core's CREATE EXTENSION / ALTER EXTENSION and custom-type machinery, so core's Nov-2026 fixes for these CVEs never reach pg_tle's install, update, and type-creation paths. Re-apply the equivalent hardening. CVE-2026-6467 (src/tleextension.c): lock the target schema, each required extension and its schema, and the extension being updated; resolve schemas and extensions through get_object_address() so they are locked; reject a temporary schema or "$user" as the extension schema or a required extension's schema; and hard-fail on a missing required schema instead of silently skipping it. CheckNamespaceLockedByMe() wraps LockHeldByMe() (which gained an "orstronger" argument in PostgreSQL 17) and is compiled only under USE_ASSERT_CHECKING. The schema locks block a concurrent ALTER SCHEMA ... RENAME only when the server's RENAME also locks the schema (the core half of the fix). CVE-2026-120153 (src/tleextension.c): replace the inline @extowner@/@extschema@ checks with a shared check_substitution_name() that also rejects comment delimiters ("--", "/*", "*/"), newlines and carriage returns, and substitution tokens ("@extowner@", "@extschema", "MODULE_PATHNAME"), in addition to the quoting characters the existing CVE-2023-39417 check already covered. CVE-2026-116316 (src/datatype.c): make create_shell_type() and pg_tle_create_base_type_internal() refuse to create a type in a temporary schema within a security-restricted operation. Core can skip base and shell types there because creating them requires superuser; pg_tle allows a non-superuser member of pgtle_admin, so the guard is needed here. Tests (test/): pg_tle_extension_script_hardening.sql and pg_tle_datatype_restricted.sql regression tests, plus the 006_pg_tle_extension_locks.pl TAP test for concurrent sessions. The TAP rename subtests self-skip on servers whose ALTER SCHEMA RENAME does not lock the schema (older servers lacking the core CVE-2026-6467 fix). Security: CVE-2026-6467 Security: CVE-2026-120153 Security: CVE-2026-116316
sibowu-aws
force-pushed
the
cve-2026-extension-script-hardening
branch
from
November 19, 2026 18:31
d6ad576 to
67aa27c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
pg_tle vendors its own copy of core's CREATE EXTENSION / ALTER EXTENSION machinery (
tleextension.c) and custom-type creation (datatype.c), so the PostgreSQL engine fixes for three recent extension/type security issues do not reach pg_tle's install, update, and type-creation paths. This change re-applies the equivalent hardening inside pg_tle.
CVE-2026-6467 — lock extension schemas/extensions; reject temporary and "$user" schemas (tleextension.c)
Resolve the target schema and prerequisite extensions through get_object_address() so they are locked, and take AccessShareLock on each required schema via LockDatabaseObject().
Take ShareUpdateExclusiveLock on the extension in ALTER EXTENSION paths (tleExecAlterExtensionStmt, tleAlterExtensionNamespace, tleExecAlterExtensionContentsStmt, get_required_extension) to exclude a concurrent ALTER EXTENSION UPDATE, and scan pg_extension by OID.
Reject a temporary namespace or "$user" as the extension schema or a required extension's schema, and hard-fail on a missing required schema instead of silently dropping it from search_path.
CheckNamespaceLockedByMe() wraps LockHeldByMe() (which gained an orstronger argument in PostgreSQL 17) and is compiled only under USE_ASSERT_CHECKING. The schema locks block a concurrent ALTER SCHEMA ... RENAME only when the server's RENAME also locks the schema (the core half of this fix).
CVE-2026-120153 — reject unsafe @extowner@ / @extschema@ substitution names (tleextension.c)
Replace the inline substitution checks with a shared check_substitution_name() that, in addition to the quoting characters the existing check already covered, also rejects comment delimiters (--, /*, */), newlines/carriage returns, and substitution tokens (@extowner@, @extschema, MODULE_PATHNAME).
CVE-2026-116316 — block temporary-schema type creation in a security-restricted operation (datatype.c)
create_shell_type() and the base-type creation path now refuse to create a type in a temporary schema while InSecurityRestrictedOperation(). Core can skip this for base/shell types because it requires superuser to create them; pg_tle allows a non-superuser member of pgtle_admin, so the guard is needed here.
Tests (test/)
pg_tle_extension_script_hardening.sql: unsafe @extschema@/@extowner@ names are rejected; a temporary schema or "$user" is rejected as the extension or required-extension schema, on CREATE EXTENSION and ALTER EXTENSION UPDATE; and CREATE/ALTER EXTENSION hold the expected schema and extension locks.
pg_tle_datatype_restricted.sql: pgtle.create_shell_type / create_base_type refuse type creation in a temporary schema within a security-restricted operation (reproduced via REFRESH MATERIALIZED VIEW), while the same creation succeeds outside the restricted operation and in a normal schema.
006_pg_tle_extension_locks.pl: concurrent sessions — a second ALTER EXTENSION UPDATE waits for the first and resumes from the committed version; ALTER SCHEMA RENAME of a TLE's schema waits for an open CREATE EXTENSION or ALTER EXTENSION UPDATE. The rename subtests self-skip on servers whose ALTER SCHEMA RENAME does not lock the schema.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.