pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix possible crash when RI fast-path metadata is invalidated mid
Date: Tue, 06 Oct 2026 00:04:57 +0000
Message-ID: <E1xDsfx-00000000ThE-1EbE@gemulon.postgresql.org> (raw)

Fix possible crash when RI fast-path metadata is invalidated mid-check

ri_FastPathCheck() read riinfo->fpmeta again after
ri_CheckFunctionPermissions(), which looks up catalog entries and so
can process invalidation messages.  If one of them reaches
InvalidateConstraintCacheCallBack() for the constraint, as a pg_amop
change or a cache reset would, the callback detaches the metadata and
sets riinfo->fpmeta to NULL, which build_index_scankeys() then
dereferences.

The callback already defers freeing detached metadata until
AtEOXact_RI(), and its comment assumes callers keep their own pointer
to it, so use a local pointer instead of riinfo->fpmeta.

There is no test, as hitting this needs an invalidation to arrive
during those catalog lookups.

Discussion: https://postgr.es/m/CA+HiwqFaipkMsZ8XP-9sMk21h0Q7rih=NpJQXsBAaD39VtnrOA@mail.gmail.com

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ad3b33d7824e3c49699ace1788acb1b07bfa69f1

Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1xDsfx-00000000ThE-1EbE@gemulon.postgresql.org>
Permalink:  ../E1xDsfx-00000000ThE-1EbE@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xDsfx-00000000ThE-1EbE@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: amitlan@postgresql.org
  Subject: Re: pgsql: Fix possible crash when RI fast-path metadata is invalidated mid
  In-Reply-To: <E1xDsfx-00000000ThE-1EbE@gemulon.postgresql.org>
  References: <E1xDsfx-00000000ThE-1EbE@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