pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix lookups in pg_{clear,restore}_{attribute,relation}_stats().
Date: Wed, 15 Oct 2025 17:49:27 +0000
Message-ID: <E1v95ct-001r9w-0N@gemulon.postgresql.org> (raw)

Fix lookups in pg_{clear,restore}_{attribute,relation}_stats().

Presently, these functions look up the relation's OID, lock it, and
then check privileges.  Not only does this approach provide no
guarantee that the locked relation matches the arguments of the
lookup, but it also allows users to briefly lock relations for
which they do not have privileges, which might enable
denial-of-service attacks.  This commit adjusts these functions to
use RangeVarGetRelidExtended(), which is purpose-built to avoid
both of these issues.  The new RangeVarGetRelidCallback function is
somewhat complicated because it must handle both tables and
indexes, and for indexes, we must check privileges on the parent
table and lock it first.  Also, it needs to handle a couple of
extremely unlikely race conditions involving concurrent OID reuse.

A downside of this change is that the coding doesn't allow for
locking indexes in AccessShare mode anymore; everything is locked
in ShareUpdateExclusive mode.  Per discussion, the original choice
of lock levels was intended for a now defunct implementation that
used in-place updates, so we believe this change is okay.

Reviewed-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/Z8zwVmGzXyDdkAXj%40nathan
Backpatch-through: 18

Branch
------
REL_18_STABLE

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

Modified Files
--------------
src/backend/statistics/attribute_stats.c   |  16 +--
src/backend/statistics/relation_stats.c    |   8 +-
src/backend/statistics/stat_utils.c        | 152 +++++++++++++++--------------
src/include/statistics/stat_utils.h        |   8 +-
src/test/regress/expected/stats_import.out |   6 +-
5 files changed, 103 insertions(+), 87 deletions(-)



view thread (2+ messages)

Message-ID: <E1v95ct-001r9w-0N@gemulon.postgresql.org>
Permalink:  ../E1v95ct-001r9w-0N@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1v95ct-001r9w-0N@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: nathan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix lookups in pg_{clear,restore}_{attribute,relation}_stats().
  In-Reply-To: <E1v95ct-001r9w-0N@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