pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix mishandling of column-level SELECT privileges for join alias
Date: Mon, 08 Feb 2021 15:14:27 +0000
Message-ID: <E1l98F9-0008V7-RA@gemulon.postgresql.org> (raw)

Fix mishandling of column-level SELECT privileges for join aliases.

scanNSItemForColumn, expandNSItemAttrs, and ExpandSingleTable would
pass the wrong RTE to markVarForSelectPriv when dealing with a join
ParseNamespaceItem: they'd pass the join RTE, when what we need to
mark is the base table that the join column came from.  The end
result was to not fill the base table's selectedCols bitmap correctly,
resulting in an understatement of the set of columns that are read
by the query.  The executor would still insist on there being at
least one selectable column; but with a correctly crafted query,
a user having SELECT privilege on just one column of a table would
nonetheless be allowed to read all its columns.

To fix, make markRTEForSelectPriv fetch the correct RTE for itself,
ignoring the possibly-mismatched RTE passed by the caller.  Later,
we'll get rid of some now-unused RTE arguments, but that risks
API breaks so we won't do it in released branches.

This problem was introduced by commit 9ce77d75c, so back-patch
to v13 where that came in.  Thanks to Sven Klemm for reporting
the problem.

Security: CVE-2021-20229

Branch
------
master

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

Modified Files
--------------
src/backend/parser/parse_relation.c      | 43 ++++++++++++++---------------
src/backend/parser/parse_target.c        |  8 ++++--
src/test/regress/expected/privileges.out | 46 ++++++++++++++++++++++++++++++++
src/test/regress/sql/privileges.sql      | 19 +++++++++++++
4 files changed, 93 insertions(+), 23 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1l98F9-0008V7-RA@gemulon.postgresql.org>
Permalink:  ../E1l98F9-0008V7-RA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1l98F9-0008V7-RA@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: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix mishandling of column-level SELECT privileges for join alias
  In-Reply-To: <E1l98F9-0008V7-RA@gemulon.postgresql.org>
  References: <E1l98F9-0008V7-RA@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