Subject: pgsql: Require superuser to install a non-built-in selectivity estimato

From: Tom Lane <[email-masked]>
Date: Mon, 09 Feb 2026 15:15:05 +0000

Require superuser to install a non-built-in selectivity estimator.

Selectivity estimators come in two flavors: those that make specific
assumptions about the data types they are working with, and those
that don't.  Most of the built-in estimators are of the latter kind
and are meant to be safely attachable to any operator.  If the
operator does not behave as the estimator expects, you might get a
poor estimate, but it won't crash.

However, estimators that do make datatype assumptions can malfunction
if they are attached to the wrong operator, since then the data they
get from pg_statistic may not be of the type they expect.  This can
rise to the level of a security problem, even permitting arbitrary
code execution by a user who has the ability to create SQL objects.

To close this hole, establish a rule that built-in estimators are
required to protect themselves against being called on the wrong type
of data.  It does not seem practical however to expect estimators in
extensions to reach a similar level of security, at least not in the
near term.  Therefore, also establish a rule that superuser privilege
is required to attach a non-built-in estimator to an operator.
We expect that this restriction will have little negative impact on
extensions, since estimators generally have to be written in C and
thus superuser privilege is required to create them in the first
place.

This commit changes the privilege checks in CREATE/ALTER OPERATOR
to enforce the rule about superuser privilege, and fixes a couple
of built-in estimators that were making datatype assumptions without
sufficiently checking that they're valid.

Reported-by: Daniel Firer as part of zeroday.cloud
Author: Tom Lane <[email-masked]>
Reviewed-by: Noah Misch <[email-masked]>
Security: CVE-2026-2004
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/841d42cc4e2f9ca1cf59758fc15619b00a11e148

Modified Files
--------------
src/backend/commands/operatorcmds.c      | 57 +++++++++++++++++++++++++-------
src/backend/tsearch/ts_selfuncs.c        |  8 +++--
src/backend/utils/adt/network_selfuncs.c | 48 ++++++++++++++++++---------
3 files changed, 83 insertions(+), 30 deletions(-)