Add a permission check to pg_stat_get_backend_subxact()

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Add a permission check to pg_stat_get_backend_subxact()
Date: 2026-09-08 00:33:05
Message-ID: CAGRkXqTBZ+zbVuDC8xGEB6Btj61hsui5H5nGqzFBDyOXc=4bjQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

pg_stat_get_backend_subxact() does not check the caller's permissions.
Every other function in the "Per-Backend Statistics Functions" table
that reports what a session is doing calls HAS_PGSTAT_PERMISSIONS()
first and returns NULL to a caller who may not see it. This one is the
only exception.

I reported this to pgsql-security first. Michael Paquier replied that
it is not a vulnerability, since the count and the flag are of no use to
an unprivileged user, and suggested that a consistency fix on HEAD be
discussed here.

The patch:

- adds the HAS_PGSTAT_PERMISSIONS() check, with a regression test that
fails without it;

- documents the rule above that table. The table says nothing about
permissions today; the rule is only written down for the dynamic
statistics views;

- corrects one column name in the docs: subxact_overflow should be
subxact_overflowed.

pid, dbid, userid and idset stay open to everyone, and I think that is
right: they leak nothing new, since pg_stat_get_activity() already hands
datid, pid, usesysid and application_name to every caller before it
reaches its permission check. subxact_count and subxact_overflowed are
different. They are not columns of pg_stat_activity at all, so this
function is the only way to read them, and today it is an unchecked one.

Thanks,
Shihao

Attachment Content-Type Size
0001-Make-pg_stat_get_backend_subxact-respect-statistics-.patch application/octet-stream 6.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Koshi Shibagaki (Fujitsu) 2026-09-08 01:01:36 Re: [PATCH] Move pgcrypto's fips_mode() function to core
Previous Message Ayoub Kazar 2026-09-08 00:27:14 Re: Speed up COPY TO text/CSV parsing using SIMD