From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix race condition adding a DEFAULT expression to a function
Date: Mon, 09 Nov 2026 14:21:55 +0000
Message-ID: <E1xQQFv-000000003Vz-1U0R@gemulon.postgresql.org> (raw)
Fix race condition adding a DEFAULT expression to a function
Because check_composite_type_dependency() didn't hold a lock while
inspecting the pg_proc entry, it was possible that the dependency was
deemed harmless, but concurrently, another backend added a DEFAULT
expression to the function that should've been rejected. To fix, hold
an AccessShareLock on the pg_proc object while we inspect it, and on
the other side of the story, hold an AccessExclusiveLock on the
pg_proc object when modifying it.
Note that we don't lock functions or other objects except relations
when using them in queries, so the AccessExclusiveLock doesn't prevent
concurrent queries using the function.
This also adds locking to other objects (constraints, types) inspected
in check_composite_type_dependency(), although that is just pro forma,
because there is no DDL to replace the expression of an existing CHECK
constraint, and altering a rowtype already holds a lock that conflicts
with an ALTER DOMAIN SET DEFAULT expression on a domain over the same
rowtype.
Relations don't have this problem, because there is no DDL command to
alter an existing table's PARTITION BY expression, nor an existing
index's expressions or quals. The OF type can be altered, but AFAICS
we have sufficient locking in place for that.
Reviewed-by: Andres Freund <andres@anarazel.de>
Security: CVE-2026-6460
Backpatch-through: 14
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/f36ac883c8aaa548729eef7e53ffc42be96fb8d1
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Modified Files
--------------
src/backend/catalog/pg_proc.c | 13 +++++++++++++
src/backend/commands/tablecmds.c | 13 +++++++++++--
src/test/isolation/expected/type-ddl-locking.out | 12 ++++++++++++
src/test/isolation/specs/type-ddl-locking.spec | 15 +++++++++++++++
4 files changed, 51 insertions(+), 2 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: noah@leadboat.com
Subject: Re: pgsql: Fix race condition adding a DEFAULT expression to a function
In-Reply-To: <E1xQQFv-000000003Vz-1U0R@gemulon.postgresql.org>
References: <E1xQQFv-000000003Vz-1U0R@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox