]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Run REFRESH MATERIALIZED VIEW CONCURRENTLY in right security context
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 5 Feb 2024 09:01:23 +0000 (11:01 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 5 Feb 2024 09:03:26 +0000 (11:03 +0200)
commitf2fdea198b3d0ab30b9e8478a762488ecebabd88
treea591566fe0fa56a1160cfbf18ece29461946f7a5
parent9a3cf3477617d8f4e296bc0b9f69d956dc601a74
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
src/backend/commands/matview.c