postgresql/src/backend
Heikki Linnakangas 6214e2b228 Fix permission checks on constraint violation errors on partitions.
If a cross-partition UPDATE violates a constraint on the target partition,
and the columns in the new partition are in different physical order than
in the parent, the error message can reveal columns that the user does not
have SELECT permission on. A similar bug was fixed earlier in commit
804b6b6db4.

The cause of the bug is that the callers of the
ExecBuildSlotValueDescription() function got confused when constructing
the list of modified columns. If the tuple was routed from a parent, we
converted the tuple to the parent's format, but the list of modified
columns was grabbed directly from the child's RTE entry.

ExecUpdateLockMode() had a similar issue. That lead to confusion on which
columns are key columns, leading to wrong tuple lock being taken on tables
referenced by foreign keys, when a row is updated with INSERT ON CONFLICT
UPDATE. A new isolation test is added for that corner case.

With this patch, the ri_RangeTableIndex field is no longer set for
partitions that don't have an entry in the range table. Previously, it was
set to the RTE entry of the parent relation, but that was confusing.

NOTE: This modifies the ResultRelInfo struct, replacing the
ri_PartitionRoot field with ri_RootResultRelInfo. That's a bit risky to
backpatch, because it breaks any extensions accessing the field. The
change that ri_RangeTableIndex is not set for partitions could potentially
break extensions, too. The ResultRelInfos are visible to FDWs at least,
and this patch required small changes to postgres_fdw. Nevertheless, this
seem like the least bad option. I don't think these fields widely used in
extensions; I don't think there are FDWs out there that uses the FDW
"direct update" API, other than postgres_fdw. If there is, you will get a
compilation error, so hopefully it is caught quickly.

Backpatch to 11, where support for both cross-partition UPDATEs, and unique
indexes on partitioned tables, were added.

Reviewed-by: Amit Langote
Security: CVE-2021-3393
2021-02-08 11:01:51 +02:00
..
access Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:51 +02:00
bootstrap Update copyright for 2021 2021-01-02 13:06:25 -05:00
catalog Disallow converting an inheritance child table to a view. 2021-02-06 15:17:01 -05:00
commands Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:51 +02:00
executor Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:51 +02:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Update copyright for 2021 2021-01-02 13:06:25 -05:00
lib Update copyright for 2021 2021-01-02 13:06:25 -05:00
libpq Introduce --with-ssl={openssl} as a configure option 2021-02-01 19:19:44 +09:00
main Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodes Remove [Merge]AppendPath.partitioned_rels. 2021-02-01 14:43:54 -05:00
optimizer Remove [Merge]AppendPath.partitioned_rels. 2021-02-01 14:43:54 -05:00
parser SEARCH and CYCLE clauses 2021-02-01 14:32:51 +01:00
partitioning Remove [Merge]AppendPath.partitioned_rels. 2021-02-01 14:43:54 -05:00
po Translation updates 2020-05-18 12:49:30 +02:00
port Refactor Windows error message for easier translation 2021-02-04 13:31:13 +01:00
postmaster Add pg_stat_database counters for sessions and session time 2021-01-17 13:52:31 +01:00
regex Fix ancient bug in parsing of BRE-mode regular expressions. 2021-01-08 12:16:00 -05:00
replication Clarify comment in tablesync.c 2021-02-04 16:02:31 +09:00
rewrite Revert "Propagate CTE property flags when copying a CTE list into a rule." 2021-02-07 12:54:08 -05:00
snowball Update copyright for 2021 2021-01-02 13:06:25 -05:00
statistics Update copyright for 2021 2021-01-02 13:06:25 -05:00
storage Rename removable xid function for consistency. 2021-02-07 10:11:14 -08:00
tcop Avoid crash when rolling back within a prepared statement. 2021-02-03 19:38:43 -05:00
tsearch Fix parsing of complex morphs to tsquery 2021-01-31 20:14:29 +03:00
utils Build in some knowledge about foreign-key relationships in the catalogs. 2021-02-02 17:11:55 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Update copyright for 2021 2021-01-02 13:06:25 -05:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Add missing gettext triggers 2020-04-28 13:35:40 +02:00