diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-01-03 21:24:26 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-01-03 21:24:26 +0000 |
commit | 46cf9c260d11d7288769de4917aa1d86b52d1e91 (patch) | |
tree | 20941a29aa9d777bb0ecf53082034d756934da74 /src/backend/commands/analyze.c | |
parent | 8b1de3b515b80e86dbef5fcbcc29e5e3256de779 (diff) | |
download | postgresql-46cf9c260d11d7288769de4917aa1d86b52d1e91.tar.gz postgresql-46cf9c260d11d7288769de4917aa1d86b52d1e91.zip |
Make standard maintenance operations (including VACUUM, ANALYZE, REINDEX,
and CLUSTER) execute as the table owner rather than the calling user, using
the same privilege-switching mechanism already used for SECURITY DEFINER
functions. The purpose of this change is to ensure that user-defined
functions used in index definitions cannot acquire the privileges of a
superuser account that is performing routine maintenance. While a function
used in an index is supposed to be IMMUTABLE and thus not able to do anything
very interesting, there are several easy ways around that restriction; and
even if we could plug them all, there would remain a risk of reading sensitive
information and broadcasting it through a covert channel such as CPU usage.
To prevent bypassing this security measure, execution of SET SESSION
AUTHORIZATION and SET ROLE is now forbidden within a SECURITY DEFINER context.
Thanks to Itagaki Takahiro for reporting this vulnerability.
Security: CVE-2007-6600
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r-- | src/backend/commands/analyze.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index e5cf86621de..d694600dc7b 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.89.2.1 2005/11/22 18:23:06 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.89.2.2 2008/01/03 21:24:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -112,6 +112,8 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) double totalrows, totaldeadrows; HeapTuple *rows; + Oid save_userid; + bool save_secdefcxt; if (vacstmt->verbose) elevel = INFO; @@ -200,6 +202,13 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) RelationGetRelationName(onerel)))); /* + * Switch to the table owner's userid, so that any index functions are + * run as that user. + */ + GetUserIdAndContext(&save_userid, &save_secdefcxt); + SetUserIdAndContext(onerel->rd_rel->relowner, true); + + /* * Determine which columns to analyze * * Note that system attributes are never analyzed. @@ -318,9 +327,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) onerel->rd_rel->relisshared, 0, 0); - vac_close_indexes(nindexes, Irel, AccessShareLock); - relation_close(onerel, AccessShareLock); - return; + goto cleanup; } /* @@ -439,6 +446,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) totalrows, totaldeadrows); } + /* We skip to here if there were no analyzable columns */ +cleanup: + /* Done with indexes */ vac_close_indexes(nindexes, Irel, NoLock); @@ -448,6 +458,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) * we made in pg_statistic.) */ relation_close(onerel, NoLock); + + /* Restore userid */ + SetUserIdAndContext(save_userid, save_secdefcxt); } /* |