mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +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/tcop/utility.c,v 1.321 2009/12/07 05:22:22 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.322 2009/12/09 21:57:51 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -225,6 +225,25 @@ check_xact_readonly(Node *parsetree)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* CheckRestrictedOperation: throw error for hazardous command if we're
|
||||
* inside a security restriction context.
|
||||
*
|
||||
* This is needed to protect session-local state for which there is not any
|
||||
* better-defined protection mechanism, such as ownership.
|
||||
*/
|
||||
static void
|
||||
CheckRestrictedOperation(const char *cmdname)
|
||||
{
|
||||
if (InSecurityRestrictedOperation())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
/* translator: %s is name of a SQL command, eg PREPARE */
|
||||
errmsg("cannot execute %s within security-restricted operation",
|
||||
cmdname)));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ProcessUtility
|
||||
* general utility function invoker
|
||||
@ -390,6 +409,7 @@ ProcessUtility(Node *parsetree,
|
||||
{
|
||||
ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
|
||||
|
||||
CheckRestrictedOperation("CLOSE");
|
||||
PerformPortalClose(stmt->portalname);
|
||||
}
|
||||
break;
|
||||
@ -586,6 +606,7 @@ ProcessUtility(Node *parsetree,
|
||||
break;
|
||||
|
||||
case T_PrepareStmt:
|
||||
CheckRestrictedOperation("PREPARE");
|
||||
PrepareQuery((PrepareStmt *) parsetree, queryString);
|
||||
break;
|
||||
|
||||
@ -595,6 +616,7 @@ ProcessUtility(Node *parsetree,
|
||||
break;
|
||||
|
||||
case T_DeallocateStmt:
|
||||
CheckRestrictedOperation("DEALLOCATE");
|
||||
DeallocateQuery((DeallocateStmt *) parsetree);
|
||||
break;
|
||||
|
||||
@ -885,6 +907,7 @@ ProcessUtility(Node *parsetree,
|
||||
{
|
||||
ListenStmt *stmt = (ListenStmt *) parsetree;
|
||||
|
||||
CheckRestrictedOperation("LISTEN");
|
||||
Async_Listen(stmt->conditionname);
|
||||
}
|
||||
break;
|
||||
@ -893,6 +916,7 @@ ProcessUtility(Node *parsetree,
|
||||
{
|
||||
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
|
||||
|
||||
CheckRestrictedOperation("UNLISTEN");
|
||||
if (stmt->conditionname)
|
||||
Async_Unlisten(stmt->conditionname);
|
||||
else
|
||||
@ -936,6 +960,8 @@ ProcessUtility(Node *parsetree,
|
||||
break;
|
||||
|
||||
case T_DiscardStmt:
|
||||
/* should we allow DISCARD PLANS? */
|
||||
CheckRestrictedOperation("DISCARD");
|
||||
DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user