Prevent indirect security attacks via changing session-local state within
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 9 Dec 2009 21:58:30 +0000 (21:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 9 Dec 2009 21:58:30 +0000 (21:58 +0000)
commitab4bbf941f0cf5e8fc1b2395ea75be98dd385794
tree569fc19327bcfe2cfef7489712a9e5ed6168eee9
parent0a699bf3aa11a714033043b0f62643e401f7de56
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
15 files changed:
src/backend/access/transam/xact.c
src/backend/catalog/index.c
src/backend/commands/analyze.c
src/backend/commands/schemacmds.c
src/backend/commands/tablecmds.c
src/backend/commands/vacuum.c
src/backend/executor/execMain.c
src/backend/tcop/utility.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/fmgr/fmgr.c
src/backend/utils/init/miscinit.c
src/backend/utils/misc/guc.c
src/include/miscadmin.h
src/include/utils/guc.h
src/include/utils/guc_tables.h