pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix race condition adding a DEFAULT expression to a function
3+ messages / 1 participants
[nested] [flat]

* pgsql: Fix race condition adding a DEFAULT expression to a function
@ 2026-11-09 14:21 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Details
-------
https://git.postgresql.org/pg/commitdiff/af5f25e7b063bd5f9d5b82bd58248a3edee16ec3
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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix race condition adding a DEFAULT expression to a function
@ 2026-11-09 14:21 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix race condition adding a DEFAULT expression to a function
@ 2026-11-09 14:22 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2026-11-09 14:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ff6d9deca78688b211b88329d9ac484df726b441
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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-11-09 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 14:21 pgsql: Fix race condition adding a DEFAULT expression to a function Noah Misch <noah@leadboat.com>
2026-11-09 14:21 pgsql: Fix race condition adding a DEFAULT expression to a function Noah Misch <noah@leadboat.com>
2026-11-09 14:22 pgsql: Fix race condition adding a DEFAULT expression to a function Noah Misch <noah@leadboat.com>

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