pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: pgsql-committers@postgresql.org
Subject: pgsql: Plug RLS related information leak in pg_stats view.
Date: Tue, 28 Jul 2015 20:22:16 +0000
Message-ID: <E1ZKBOC-0005Gh-Ci@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Plug RLS related information leak in pg_stats view.

The pg_stats view is supposed to be restricted to only show rows
about tables the user can read. However, it sometimes can leak
information which could not otherwise be seen when row level security
is enabled. Fix that by not showing pg_stats rows to users that would
be subject to RLS on the table the row is related to. This is done
by creating/using the newly introduced SQL visible function,
row_security_active().

Along the way, clean up three call sites of check_enable_rls(). The second
argument of that function should only be specified as other than
InvalidOid when we are checking as a different user than the current one,
as in when querying through a view. These sites were passing GetUserId()
instead of InvalidOid, which can cause the function to return incorrect
results if the current user has the BYPASSRLS privilege and row_security
has been set to OFF.

Additionally fix a bug causing RI Trigger error messages to unintentionally
leak information when RLS is enabled, and other minor cleanup and
improvements. Also add WITH (security_barrier) to the definition of pg_stats.

Bumped CATVERSION due to new SQL functions and pg_stats view definition.

Back-patch to 9.5 where RLS was introduced. Reported by Yaroslav.
Patch by Joe Conway and Dean Rasheed with review and input by
Michael Paquier and Stephen Frost.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/7b4bfc87d5e73c94ae1591c482f626a011498915

Modified Files
--------------
doc/src/sgml/func.sgml                    |   16 +++++++++
src/backend/access/index/genam.c          |    2 +-
src/backend/catalog/system_views.sql      |    6 ++--
src/backend/executor/execMain.c           |    2 +-
src/backend/rewrite/rowsecurity.c         |   16 ++-------
src/backend/utils/adt/ri_triggers.c       |    4 ++-
src/backend/utils/cache/plancache.c       |    7 +---
src/backend/utils/init/miscinit.c         |   14 +++++++-
src/backend/utils/misc/rls.c              |   53 ++++++++++++++++++++++++++++-
src/include/catalog/catversion.h          |    2 +-
src/include/catalog/pg_proc.h             |    6 ++++
src/include/miscadmin.h                   |    1 +
src/include/utils/builtins.h              |    4 +++
src/test/regress/expected/rowsecurity.out |   38 +++++++++++++++++++--
src/test/regress/expected/rules.out       |    2 +-
src/test/regress/sql/rowsecurity.sql      |   17 ++++++++-
16 files changed, 159 insertions(+), 31 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


view thread (4+ messages)  latest in thread

Message-ID: <E1ZKBOC-0005Gh-Ci@gemulon.postgresql.org>
Permalink:  ../E1ZKBOC-0005Gh-Ci@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ZKBOC-0005Gh-Ci@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: mail@joeconway.com
  Subject: Re: pgsql: Plug RLS related information leak in pg_stats view.
  In-Reply-To: <E1ZKBOC-0005Gh-Ci@gemulon.postgresql.org>
  References: <E1ZKBOC-0005Gh-Ci@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