pgsql: Allow access to child table statistics if user can read parent t - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Allow access to child table statistics if user can read parent t
Date
Msg-id E1iZgio-00041z-RI@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Allow access to child table statistics if user can read parent table.

The fix for CVE-2017-7484 disallowed use of pg_statistic data for
planning purposes if the user would not be able to select the associated
column and a non-leakproof function is to be applied to the statistics
values.  That turns out to disable use of pg_statistic data in some
common cases involving inheritance/partitioning, where the user does
have permission to select from the parent table that was actually named
in the query, but not from a child table whose stats are needed.  Since,
in non-corner cases, the user *can* select the child table's data via
the parent, this restriction is not actually useful from a security
standpoint.  Improve the logic so that we also check the permissions of
the originally-named table, and allow access if select permission exists
for that.

When checking access to stats for a simple child column, we can map
the child column number back to the parent, and perform this test
exactly (including not allowing access if the child column isn't
exposed by the parent).  For expression indexes, the current logic
just insists on whole-table select access, and this patch allows
access if the user can select the whole parent table.  In principle,
if the child table has extra columns, this might allow access to
stats on columns the user can't read.  In practice, it's unlikely
that the planner is going to do any stats calculations involving
expressions that are not visible to the query, so we'll ignore that
fine point for now.  Perhaps someday we'll improve that logic to
detect exactly which columns are used by an expression index ...
but today is not that day.

Back-patch to v11.  The issue was created in 9.2 and up by the
CVE-2017-7484 fix, but this patch depends on the append_rel_array[]
planner data structure which only exists in v11 and up.  In
practice the issue is most urgent with partitioned tables, so
fixing v11 and later should satisfy much of the practical need.

Dilip Kumar and Amit Langote, with some kibitzing by me

Discussion: https://postgr.es/m/3876.1531261875@sss.pgh.pa.us

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/21a4edd1281de5efd09f1cf5c6073af14a2de409

Modified Files
--------------
src/backend/utils/adt/selfuncs.c      | 128 ++++++++++++++++++++++++++++++++++
src/test/regress/expected/inherit.out |  74 ++++++++++++++++++++
src/test/regress/sql/inherit.sql      |  38 ++++++++++
3 files changed, 240 insertions(+)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pgsql: Close stdin where it's not needed in TestLib.pm procedures
Next
From: Tom Lane
Date:
Subject: Re: pgsql: Close stdin where it's not needed in TestLib.pm procedures