diff options
author | Noah Misch <noah@leadboat.com> | 2020-11-09 07:32:09 -0800 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2020-11-09 07:32:12 -0800 |
commit | c90c84b3f797a54a40ebc6795fbd743bdf44adad (patch) | |
tree | e697084d901924faf74064ad58dbc43b50f590df /src/backend/access/transam/xact.c | |
parent | 62e7ae75f441e7c91f446b05f5b206fe01e34f0c (diff) | |
download | postgresql-c90c84b3f797a54a40ebc6795fbd743bdf44adad.tar.gz postgresql-c90c84b3f797a54a40ebc6795fbd743bdf44adad.zip |
In security-restricted operations, block enqueue of at-commit user code.
Specifically, this blocks DECLARE ... WITH HOLD and firing of deferred
triggers within index expressions and materialized view queries. An
attacker having permission to create non-temp objects in at least one
schema could execute arbitrary SQL functions under the identity of the
bootstrap superuser. One can work around the vulnerability by disabling
autovacuum and not manually running ANALYZE, CLUSTER, REINDEX, CREATE
INDEX, VACUUM FULL, or REFRESH MATERIALIZED VIEW. (Don't restore from
pg_dump, since it runs some of those commands.) Plain VACUUM (without
FULL) is safe, and all commands are fine when a trusted user owns the
target object. Performance may degrade quickly under this workaround,
however. Back-patch to 9.5 (all supported versions).
Reviewed by Robert Haas. Reported by Etienne Stalmans.
Security: CVE-2020-25695
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r-- | src/backend/access/transam/xact.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index cd30b62d365..9beab6d44da 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2067,9 +2067,10 @@ CommitTransaction(void) /* * Do pre-commit processing that involves calling user-defined code, such - * as triggers. Since closing cursors could queue trigger actions, - * triggers could open cursors, etc, we have to keep looping until there's - * nothing left to do. + * as triggers. SECURITY_RESTRICTED_OPERATION contexts must not queue an + * action that would run here, because that would bypass the sandbox. + * Since closing cursors could queue trigger actions, triggers could open + * cursors, etc, we have to keep looping until there's nothing left to do. */ for (;;) { @@ -2087,9 +2088,6 @@ CommitTransaction(void) break; } - CallXactCallbacks(is_parallel_worker ? XACT_EVENT_PARALLEL_PRE_COMMIT - : XACT_EVENT_PRE_COMMIT); - /* * The remaining actions cannot call any user-defined code, so it's safe * to start shutting down within-transaction services. But note that most @@ -2097,6 +2095,9 @@ CommitTransaction(void) * the transaction-abort path. */ + CallXactCallbacks(is_parallel_worker ? XACT_EVENT_PARALLEL_PRE_COMMIT + : XACT_EVENT_PRE_COMMIT); + /* If we might have parallel workers, clean them up now. */ if (IsInParallelMode()) AtEOXact_Parallel(true); |