postgresql/src/backend
Tom Lane 553d2ec271 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
2019-11-26 14:41:48 -05:00
..
access Refactor WAL file-reading code into WALRead() 2019-11-25 15:04:54 -03:00
bootstrap Remove configure --disable-float4-byval 2019-11-21 18:29:21 +01:00
catalog Add object TRUNCATE hook 2019-11-23 10:39:20 -05:00
commands Doc: improve discussion of race conditions involved in LISTEN. 2019-11-24 18:03:39 -05:00
executor Don't shut down Gather[Merge] early under Limit. 2019-11-26 08:30:24 +05:30
foreign Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
jit Make the order of the header file includes consistent in backend modules. 2019-11-12 08:30:16 +05:30
lib Make StringInfo available to frontend code. 2019-11-05 14:56:40 -08:00
libpq Make the order of the header file includes consistent. 2019-11-25 08:08:57 +05:30
main Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
nodes Introduce the 'force' option for the Drop Database command. 2019-11-13 08:25:33 +05:30
optimizer Make the order of the header file includes consistent in backend modules. 2019-11-12 08:30:16 +05:30
parser Allow ALTER VIEW command to rename the column in the view. 2019-11-21 19:55:13 +09:00
partitioning Make the order of the header file includes consistent in backend modules. 2019-11-12 08:30:16 +05:30
po Translation updates 2019-06-17 15:30:20 +02:00
port Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
postmaster Use procsignal_sigusr1_handler for auxiliary processes. 2019-11-25 16:16:27 -05:00
regex Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
replication Use procsignal_sigusr1_handler for auxiliary processes. 2019-11-25 16:16:27 -05:00
rewrite Defend against self-referential views in relation_is_updatable(). 2019-11-21 16:21:43 -05:00
snowball Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
statistics Make the order of the header file includes consistent in backend modules. 2019-11-12 08:30:16 +05:30
storage Add safeguards for pg_fsync() called with incorrectly-opened fds 2019-11-26 13:32:52 +09:00
tcop Stabilize NOTIFY behavior by transmitting notifies before ReadyForQuery. 2019-11-24 14:42:59 -05:00
tsearch Make the order of the header file includes consistent in backend modules. 2019-11-12 08:30:16 +05:30
utils Allow access to child table statistics if user can read parent table. 2019-11-26 14:41:48 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00