mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Prevent indirect security attacks via changing session-local state within
an allegedly immutable index function. It was previously recognized that we had to prevent such a function from executing SET/RESET ROLE/SESSION AUTHORIZATION, or it could trivially obtain the privileges of the session user. However, since there is in general no privilege checking for changes of session-local state, it is also possible for such a function to change settings in a way that might subvert later operations in the same session. Examples include changing search_path to cause an unexpected function to be called, or replacing an existing prepared statement with another one that will execute a function of the attacker's choosing. The present patch secures VACUUM, ANALYZE, and CREATE INDEX/REINDEX against these threats, which are the same places previously deemed to need protection against the SET ROLE issue. GUC changes are still allowed, since there are many useful cases for that, but we prevent security problems by forcing a rollback of any GUC change after completing the operation. Other cases are handled by throwing an error if any change is attempted; these include temp table creation, closing a cursor, and creating or deleting a prepared statement. (In 7.4, the infrastructure to roll back GUC changes doesn't exist, so we settle for rejecting changes of "search_path" in these contexts.) Original report and patch by Gurjeet Singh, additional analysis by Tom Lane. Security: CVE-2009-4136
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.276 2009/11/23 09:58:36 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.277 2009/12/09 21:57:50 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -137,7 +137,7 @@ typedef struct TransactionStateData
|
||||
int nChildXids; /* # of subcommitted child XIDs */
|
||||
int maxChildXids; /* allocated size of childXids[] */
|
||||
Oid prevUser; /* previous CurrentUserId setting */
|
||||
bool prevSecDefCxt; /* previous SecurityDefinerContext setting */
|
||||
int prevSecContext; /* previous SecurityRestrictionContext */
|
||||
bool prevXactReadOnly; /* entry-time xact r/o state */
|
||||
struct TransactionStateData *parent; /* back link to parent */
|
||||
} TransactionStateData;
|
||||
@ -165,7 +165,7 @@ static TransactionStateData TopTransactionStateData = {
|
||||
0, /* # of subcommitted child Xids */
|
||||
0, /* allocated size of childXids[] */
|
||||
InvalidOid, /* previous CurrentUserId setting */
|
||||
false, /* previous SecurityDefinerContext setting */
|
||||
0, /* previous SecurityRestrictionContext */
|
||||
false, /* entry-time xact r/o state */
|
||||
NULL /* link to parent state block */
|
||||
};
|
||||
@ -1522,9 +1522,9 @@ StartTransaction(void)
|
||||
s->childXids = NULL;
|
||||
s->nChildXids = 0;
|
||||
s->maxChildXids = 0;
|
||||
GetUserIdAndContext(&s->prevUser, &s->prevSecDefCxt);
|
||||
/* SecurityDefinerContext should never be set outside a transaction */
|
||||
Assert(!s->prevSecDefCxt);
|
||||
GetUserIdAndSecContext(&s->prevUser, &s->prevSecContext);
|
||||
/* SecurityRestrictionContext should never be set outside a transaction */
|
||||
Assert(s->prevSecContext == 0);
|
||||
|
||||
/*
|
||||
* initialize other subsystems for new transaction
|
||||
@ -2014,13 +2014,13 @@ AbortTransaction(void)
|
||||
* Reset user ID which might have been changed transiently. We need this
|
||||
* to clean up in case control escaped out of a SECURITY DEFINER function
|
||||
* or other local change of CurrentUserId; therefore, the prior value of
|
||||
* SecurityDefinerContext also needs to be restored.
|
||||
* SecurityRestrictionContext also needs to be restored.
|
||||
*
|
||||
* (Note: it is not necessary to restore session authorization or role
|
||||
* settings here because those can only be changed via GUC, and GUC will
|
||||
* take care of rolling them back if need be.)
|
||||
*/
|
||||
SetUserIdAndContext(s->prevUser, s->prevSecDefCxt);
|
||||
SetUserIdAndSecContext(s->prevUser, s->prevSecContext);
|
||||
|
||||
/*
|
||||
* do abort processing
|
||||
@ -3860,7 +3860,7 @@ AbortSubTransaction(void)
|
||||
* Reset user ID which might have been changed transiently. (See notes in
|
||||
* AbortTransaction.)
|
||||
*/
|
||||
SetUserIdAndContext(s->prevUser, s->prevSecDefCxt);
|
||||
SetUserIdAndSecContext(s->prevUser, s->prevSecContext);
|
||||
|
||||
/*
|
||||
* We can skip all this stuff if the subxact failed before creating a
|
||||
@ -4000,7 +4000,7 @@ PushTransaction(void)
|
||||
s->savepointLevel = p->savepointLevel;
|
||||
s->state = TRANS_DEFAULT;
|
||||
s->blockState = TBLOCK_SUBBEGIN;
|
||||
GetUserIdAndContext(&s->prevUser, &s->prevSecDefCxt);
|
||||
GetUserIdAndSecContext(&s->prevUser, &s->prevSecContext);
|
||||
s->prevXactReadOnly = XactReadOnly;
|
||||
|
||||
CurrentTransactionState = s;
|
||||
|
Reference in New Issue
Block a user