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 enforcement of SELECT FOR UPDATE permissions with nested vie
Date: Sat, 14 Apr 2018 19:38:18 +0000
Message-ID: <E1f7R06-0003Hd-J0@gemulon.postgresql.org> (raw)

Fix enforcement of SELECT FOR UPDATE permissions with nested views.

SELECT FOR UPDATE on a view should require UPDATE (as well as SELECT)
permissions on the view, and then the view's owner needs those same
permissions against the relations it references, and so on all the way
down to base tables.  But ApplyRetrieveRule did things in the wrong order,
resulting in failure to mark intermediate view levels as needing UPDATE
permission.  Thus for example, if user A creates a table T and an updatable
view V1 on T, then grants only SELECT permissions on V1 to user B, B could
create a second view V2 on V1 and then would be allowed to perform SELECT
FOR UPDATE via V2 (since V1 wouldn't be checked for UPDATE permissions).

To fix, just switch the order of expanding sub-views and marking referenced
objects as needing UPDATE permission.  I think additional simplifications
are now possible, but that's distinct from the bug fix proper.

This is certainly a security issue, but the consequences are pretty minor
(just the ability to lock rows that shouldn't be lockable).  Against that
we have a small risk of breaking applications that are working as-desired,
since nested views have behaved this way since such cases worked at all.
On balance I'm inclined not to back-patch.

Per report from Alexander Lakhin.

Discussion: https://postgr.es/m/24db7b8f-3de5-e25f-7ab9-d8848351d42c@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/50c6bb022475bd9ad9c73e3b68b5152db5163b22

Modified Files
--------------
src/backend/rewrite/rewriteHandler.c          |  31 ++++---
src/test/regress/expected/updatable_views.out | 124 ++++++++++++++++++++++++++
src/test/regress/sql/updatable_views.sql      |  76 ++++++++++++++++
3 files changed, 219 insertions(+), 12 deletions(-)



Message-ID: <E1f7R06-0003Hd-J0@gemulon.postgresql.org>
Permalink:  ../E1f7R06-0003Hd-J0@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1f7R06-0003Hd-J0@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 enforcement of SELECT FOR UPDATE permissions with nested vie
  In-Reply-To: <E1f7R06-0003Hd-J0@gemulon.postgresql.org>
  References: <E1f7R06-0003Hd-J0@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