pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: plperl: Refuse to free a prepared query that is being executed.
3+ messages / 1 participants
[nested] [flat]

* pgsql: plperl: Refuse to free a prepared query that is being executed.
@ 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

plperl: Refuse to free a prepared query that is being executed.

Previously, spi_freeplan() released a prepared query's plan, and the
memory context holding it, without checking whether the query was
still running. Executing a prepared query can re-enter plperl, and the
re-entered code could free the query being run. That memory context
also holds state the running execution still needs, so freeing it
midway left that execution using freed memory and crashed the backend.
plperl is trusted, so any role able to create a function can reach
this.

Fix this by counting the executions in progress for each prepared
query and refusing spi_freeplan() while that count is above zero. A
count rather than a flag is needed because the same query can be
running more than once at a time.

Backpatch to all supported branches, where spi_freeplan() has always
freed the plan unconditionally.

Reported-by: Zheng Yu <zheng@depthfirst.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Backpatch-through: 14
Security: CVE-2026-116307

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/99c7967a799d555aeb58587d626c519da6f50340
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
src/pl/plperl/expected/plperl.out | 34 +++++++++++++++++++++++++
src/pl/plperl/plperl.c            | 53 ++++++++++++++++++++++++++++++++++++---
src/pl/plperl/sql/plperl.sql      | 34 +++++++++++++++++++++++++
3 files changed, 117 insertions(+), 4 deletions(-)



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

* pgsql: plperl: Refuse to free a prepared query that is being executed.
@ 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

plperl: Refuse to free a prepared query that is being executed.

Previously, spi_freeplan() released a prepared query's plan, and the
memory context holding it, without checking whether the query was
still running. Executing a prepared query can re-enter plperl, and the
re-entered code could free the query being run. That memory context
also holds state the running execution still needs, so freeing it
midway left that execution using freed memory and crashed the backend.
plperl is trusted, so any role able to create a function can reach
this.

Fix this by counting the executions in progress for each prepared
query and refusing spi_freeplan() while that count is above zero. A
count rather than a flag is needed because the same query can be
running more than once at a time.

Backpatch to all supported branches, where spi_freeplan() has always
freed the plan unconditionally.

Reported-by: Zheng Yu <zheng@depthfirst.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Backpatch-through: 14
Security: CVE-2026-116307

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/31d908432bd48ae7cd59260e32461a34ce5ec22b
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
src/pl/plperl/expected/plperl.out | 34 +++++++++++++++++++++++++
src/pl/plperl/plperl.c            | 53 ++++++++++++++++++++++++++++++++++++---
src/pl/plperl/sql/plperl.sql      | 34 +++++++++++++++++++++++++
3 files changed, 117 insertions(+), 4 deletions(-)



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

* pgsql: plperl: Refuse to free a prepared query that is being executed.
@ 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

plperl: Refuse to free a prepared query that is being executed.

Previously, spi_freeplan() released a prepared query's plan, and the
memory context holding it, without checking whether the query was
still running. Executing a prepared query can re-enter plperl, and the
re-entered code could free the query being run. That memory context
also holds state the running execution still needs, so freeing it
midway left that execution using freed memory and crashed the backend.
plperl is trusted, so any role able to create a function can reach
this.

Fix this by counting the executions in progress for each prepared
query and refusing spi_freeplan() while that count is above zero. A
count rather than a flag is needed because the same query can be
running more than once at a time.

Backpatch to all supported branches, where spi_freeplan() has always
freed the plan unconditionally.

Reported-by: Zheng Yu <zheng@depthfirst.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Backpatch-through: 14
Security: CVE-2026-116307

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/250405afb76579e0691267471c196bb9ea3b3e0d
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
src/pl/plperl/expected/plperl.out | 34 +++++++++++++++++++++++++
src/pl/plperl/plperl.c            | 53 ++++++++++++++++++++++++++++++++++++---
src/pl/plperl/sql/plperl.sql      | 34 +++++++++++++++++++++++++
3 files changed, 117 insertions(+), 4 deletions(-)



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


end of thread, other threads:[~2026-11-09 14:21 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: plperl: Refuse to free a prepared query that is being executed. Noah Misch <noah@leadboat.com>
2026-11-09 14:21 pgsql: plperl: Refuse to free a prepared query that is being executed. Noah Misch <noah@leadboat.com>
2026-11-09 14:21 pgsql: plperl: Refuse to free a prepared query that is being executed. 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