agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix unsafe order of operations in ResourceOwnerReleaseAll().
Date: Mon, 22 Jun 2026 22:03:33 +0000
Message-ID: <E1wbmjt-001SGR-0k@gemulon.postgresql.org> (raw)

Fix unsafe order of operations in ResourceOwnerReleaseAll().

This function called the resource-kind-specific ReleaseResource()
method for each item before deleting that item from the resowner.
That's backwards from the ordering in ResourceOwnerReleaseAllOfKind,
and it's not very safe.  If ReleaseResource throws an error then the
subsequent abort cleanup will come back here and try to release that
item again, possibly leading to a double-free or similar crash,
and in any case risking an infinite error cleanup loop.  This mistake
explains why the pgcrypto bug just fixed in 80bb0ebcc led to a crash
rather than something more benign.

Remove the item from the resowner, then call ReleaseResource,
matching the way things were done before b8bff07da.  If there
is a problem of this sort, we'd prefer to leak the item than
suffer the other likely consequences.

Per further analysis of bug #19527.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/646741.1782157515@sss.pgh.pa.us
Backpatch-through: 17

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/011eedcdc3fe04000c46881333aaa0ac70a1aa1f

Modified Files
--------------
src/backend/utils/resowner/resowner.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)



view thread (7+ messages)

Message-ID: <E1wbmjt-001SGR-0k@gemulon.postgresql.org>
Permalink:  ../E1wbmjt-001SGR-0k@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wbmjt-001SGR-0k@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix unsafe order of operations in ResourceOwnerReleaseAll().
  In-Reply-To: <E1wbmjt-001SGR-0k@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox