postgresql/src/backend
Stephen Frost 86ebf30fd6 Reset plan->row_security_env and planUserId
In the plancache, we check if the environment we planned the query under
has changed in a way which requires us to re-plan, such as when the user
for whom the plan was prepared changes and RLS is being used (and,
therefore, there may be different policies to apply).

Unfortunately, while those values were set and checked, they were not
being reset when the query was re-planned and therefore, in cases where
we change role, re-plan, and then change role again, we weren't
re-planning again.  This leads to potentially incorrect policies being
applied in cases where role-specific policies are used and a given query
is planned under one role and then executed under other roles, which
could happen under security definer functions or when a common user and
query is planned initially and then re-used across multiple SET ROLEs.

Further, extensions which made use of CopyCachedPlan() may suffer from
similar issues as the RLS-related fields were not properly copied as
part of the plan and therefore RevalidateCachedQuery() would copy in the
current settings without invalidating the query.

Fix by using the same approach used for 'search_path', where we set the
correct values in CompleteCachedPlan(), check them early on in
RevalidateCachedQuery() and then properly reset them if re-planning.
Also, copy through the values during CopyCachedPlan().

Pointed out by Ashutosh Bapat.  Reviewed by Michael Paquier.

Back-patch to 9.5 where RLS was introduced.

Security: CVE-2016-2193
2016-03-28 09:03:20 -04:00
..
access Don't use !! but != 0/NULL to force boolean evaluation. 2016-03-27 18:10:19 +02:00
bootstrap Provide much better wait information in pg_stat_activity. 2016-03-10 12:44:09 -05:00
catalog Fix DROP OPERATOR to reset oprcom/oprnegate links to the dropped operator. 2016-03-25 12:33:16 -04:00
commands Fix DROP OPERATOR to reset oprcom/oprnegate links to the dropped operator. 2016-03-25 12:33:16 -04:00
executor Fix EvalPlanQual bug when query contains both locked and not-locked rels. 2016-03-22 17:56:20 -04:00
foreign Remove a couple of useless pstrdup() calls. 2016-03-09 23:29:05 -05:00
lib Add two HyperLogLog functions 2016-01-19 17:40:15 -03:00
libpq Properly declare FeBeWaitSet. 2016-03-21 12:58:18 +01:00
main Avoid crash on old Windows with AVX2-capable CPU for VS2013 builds 2016-03-10 14:10:18 +01:00
nodes Support CREATE ACCESS METHOD 2016-03-23 23:01:35 -03:00
optimizer Avoid a couple of zero-divide scenarios in the planner. 2016-03-26 12:03:12 -04:00
parser Move psql's psqlscan.l into src/fe_utils. 2016-03-24 20:28:47 -04:00
po Translation updates 2015-06-28 23:56:55 -04:00
port Combine win32 and unix latch implementations. 2016-03-21 11:03:26 +01:00
postmaster Merge wal_level "archive" and "hot_standby" into new name "replica" 2016-03-18 23:56:03 +01:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:12:16 -05:00
replication Don't use !! but != 0/NULL to force boolean evaluation. 2016-03-27 18:10:19 +02:00
rewrite Improve error message for rejecting RETURNING clauses with dropped columns. 2016-02-29 19:11:38 -05:00
snowball Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage Fix LWLockReportWaitEnd() parameter list to be (void). 2016-03-27 22:53:31 +02:00
tcop Support CREATE ACCESS METHOD 2016-03-23 23:01:35 -03:00
tsearch Improve support of Hunspell 2016-03-17 17:23:38 +03:00
utils Reset plan->row_security_env and planUserId 2016-03-28 09:03:20 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Combine win32 and unix latch implementations. 2016-03-21 11:03:26 +01:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00