pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: plperl: Refuse to free a prepared query that is being executed.
Date: Mon, 09 Nov 2026 14:21:53 +0000
Message-ID: <E1xQQFt-000000003RP-1AFK@gemulon.postgresql.org> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <E1xQQFt-000000003RP-1AFK@gemulon.postgresql.org>
Permalink:  ../E1xQQFt-000000003RP-1AFK@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xQQFt-000000003RP-1AFK@gemulon.postgresql.org

 · 

reply

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: plperl: Refuse to free a prepared query that is being executed.
  In-Reply-To: <E1xQQFt-000000003RP-1AFK@gemulon.postgresql.org>
  References: <E1xQQFt-000000003RP-1AFK@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