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: Run REFRESH MATERIALIZED VIEW CONCURRENTLY in right security con
Date: Mon, 05 Feb 2024 09:28:32 +0000
Message-ID: <E1rWvHE-004kuw-4Z@gemulon.postgresql.org> (raw)

Run REFRESH MATERIALIZED VIEW CONCURRENTLY in right security context

The internal commands in REFRESH MATERIALIZED VIEW CONCURRENTLY are
correctly executed in SECURITY_RESTRICTED_OPERATION mode, except for
creating the temporary "diff" table, because you cannot create
temporary tables in SRO mode. But creating the temporary "diff" table
is a pretty complex CTAS command that selects from another temporary
table created earlier in the command. If you can cajole that CTAS
command to execute code defined by the table owner, the table owner
can run code with the privileges of the user running the REFRESH
command.

The proof-of-concept reported to the security team relied on CREATE
RULE to convert the internally-built temp table to a view. That's not
possible since commit b23cd185fd, and I was not able to find a
different way to turn the SELECT on the temp table into code
execution, so as far as I know this is only exploitable in v15 and
below. That's a fiddly assumption though, so apply this patch to
master and all stable versions.

Thanks to Pedro Gallegos for the report.

Security: CVE-2023-5869
Reviewed-by: Noah Misch

Branch
------
REL_13_STABLE

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

Modified Files
--------------
src/backend/commands/matview.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1rWvHE-004kuw-4Z@gemulon.postgresql.org>
Permalink:  ../E1rWvHE-004kuw-4Z@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rWvHE-004kuw-4Z@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Run REFRESH MATERIALIZED VIEW CONCURRENTLY in right security con
  In-Reply-To: <E1rWvHE-004kuw-4Z@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