mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
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
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.63.2.1 2004/10/13 22:22:03 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.63.2.2 2008/01/03 21:25:33 tgl Exp $
|
||||
*
|
||||
* ----------
|
||||
*/
|
||||
@@ -2967,7 +2967,8 @@ ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes,
|
||||
{
|
||||
void *qplan;
|
||||
Relation query_rel;
|
||||
AclId save_uid;
|
||||
AclId save_userid;
|
||||
bool save_secdefcxt;
|
||||
|
||||
/*
|
||||
* The query is always run against the FK table except when this is an
|
||||
@@ -2981,8 +2982,8 @@ ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes,
|
||||
query_rel = fk_rel;
|
||||
|
||||
/* Switch to proper UID to perform check as */
|
||||
save_uid = GetUserId();
|
||||
SetUserId(RelationGetForm(query_rel)->relowner);
|
||||
GetUserIdAndContext(&save_userid, &save_secdefcxt);
|
||||
SetUserIdAndContext(RelationGetForm(query_rel)->relowner, true);
|
||||
|
||||
/* Create the plan */
|
||||
qplan = SPI_prepare(querystr, nargs, argtypes);
|
||||
@@ -2991,7 +2992,7 @@ ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes,
|
||||
elog(ERROR, "SPI_prepare returned %d for %s", SPI_result, querystr);
|
||||
|
||||
/* Restore UID */
|
||||
SetUserId(save_uid);
|
||||
SetUserIdAndContext(save_userid, save_secdefcxt);
|
||||
|
||||
/* Save the plan if requested */
|
||||
if (cache_plan)
|
||||
@@ -3019,7 +3020,8 @@ ri_PerformCheck(RI_QueryKey *qkey, void *qplan,
|
||||
bool useCurrentSnapshot;
|
||||
int limit;
|
||||
int spi_result;
|
||||
AclId save_uid;
|
||||
AclId save_userid;
|
||||
bool save_secdefcxt;
|
||||
Datum vals[RI_MAX_NUMKEYS * 2];
|
||||
char nulls[RI_MAX_NUMKEYS * 2];
|
||||
|
||||
@@ -3095,15 +3097,15 @@ ri_PerformCheck(RI_QueryKey *qkey, void *qplan,
|
||||
limit = (expect_OK == SPI_OK_SELECT) ? 1 : 0;
|
||||
|
||||
/* Switch to proper UID to perform check as */
|
||||
save_uid = GetUserId();
|
||||
SetUserId(RelationGetForm(query_rel)->relowner);
|
||||
GetUserIdAndContext(&save_userid, &save_secdefcxt);
|
||||
SetUserIdAndContext(RelationGetForm(query_rel)->relowner, true);
|
||||
|
||||
/* Finally we can run the query. */
|
||||
spi_result = SPI_execp_current(qplan, vals, nulls,
|
||||
useCurrentSnapshot, limit);
|
||||
|
||||
/* Restore UID */
|
||||
SetUserId(save_uid);
|
||||
SetUserIdAndContext(save_userid, save_secdefcxt);
|
||||
|
||||
/* Check result */
|
||||
if (spi_result < 0)
|
||||
|
Reference in New Issue
Block a user