Reject system catalogs as logical replication targets.

The subscriber relied on the publisher refusing to add a system
catalog to a publication, and checked only the relation kind it was
about to apply into. However, the relation is named by the publisher,
and a publisher that speaks the logical replication protocol doesn't
have to be a PostgreSQL server. A malicious one can name a system
catalog, and the apply worker will write into it.

The danger is limited to subscriptions owned by a superuser. Changes
are applied as the table owner, or as the subscription owner when
run_as_owner is set, and a non-superuser can never hold write
privileges on a system catalog, so a subscription owned by a
non-superuser stops at the privilege check.

We can't depend on the publisher for this, so check the target
relation on the subscriber too. A relation that the server maintains
for its own use, such as a system catalog, must never be written by an
apply worker, and neither must a temporary relation. We don't reject
unlogged relations the way the publisher does; replicating into one is
fine. The check runs when a worker opens the target relation to apply
changes, and also when getting the relation list, so that such a
relation is never recorded in pg_subscription_rel in the first place.

The test attaches a callback of its own to the injection point, which
needs a form of injection_points_attach() that v18 and older don't
have, so it is applied to v19 and later.

Reported-by: qian zhang <[email protected]>
Author: Masahiko Sawada <[email protected]>
Reviewed-by: Ashutosh Bapat <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Backpatch-through: 14
Security: CVE-2026-120145

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7becf1984f46ee7b83f778370fc2a3b60f46f022
Author: Masahiko Sawada <[email protected]>

Modified Files
--------------
src/backend/commands/subscriptioncmds.c            |  12 +--
src/backend/executor/execReplication.c             |  50 ++++++++--
src/backend/replication/logical/relation.c         |  11 +--
src/backend/replication/logical/worker.c           |  17 ++--
src/include/executor/executor.h                    |   5 +-
.../modules/injection_points/regress_injection.c   |  27 ++++++
src/test/subscription/t/100_bugs.pl                | 107 ++++++++++++++++++++-
7 files changed, 200 insertions(+), 29 deletions(-)

Reply via email to