pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix permission checks on constraint violation errors on partitio
Date: Mon, 08 Feb 2021 09:03:46 +0000
Message-ID: <E1l92SQ-00064v-MY@gemulon.postgresql.org> (raw)

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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f50e888990d3fa197e588991b637f9e43e56e53f

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c                | 20 +++--
src/backend/access/common/tupconvert.c             | 53 +++++++++++++
src/backend/commands/copy.c                        |  1 +
src/backend/commands/explain.c                     |  2 +-
src/backend/commands/trigger.c                     | 24 +++---
src/backend/executor/execMain.c                    | 87 ++++++++++-----------
src/backend/executor/execPartition.c               | 33 ++++----
src/backend/executor/execUtils.c                   | 89 ++++++++++++++++++++++
src/backend/executor/nodeModifyTable.c             |  2 +-
src/include/access/tupconvert.h                    |  2 +
src/include/executor/executor.h                    |  7 +-
src/include/nodes/execnodes.h                      |  9 ++-
.../isolation/expected/tuplelock-partition.out     | 20 +++++
src/test/isolation/isolation_schedule              |  1 +
src/test/isolation/specs/tuplelock-partition.spec  | 32 ++++++++
src/test/regress/expected/privileges.out           | 39 ++++++++++
src/test/regress/sql/privileges.sql                | 38 +++++++++
17 files changed, 371 insertions(+), 88 deletions(-)



view thread (4+ messages)  latest in thread

Message-ID: <E1l92SQ-00064v-MY@gemulon.postgresql.org>
Permalink:  ../E1l92SQ-00064v-MY@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1l92SQ-00064v-MY@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi
  Subject: Re: pgsql: Fix permission checks on constraint violation errors on partitio
  In-Reply-To: <E1l92SQ-00064v-MY@gemulon.postgresql.org>
  References: <E1l92SQ-00064v-MY@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox