pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Reset plan->row_security_env and planUserId
2+ messages / 1 participants
[nested] [flat]

* pgsql: Reset plan->row_security_env and planUserId
@ 2016-03-28 13:04  Stephen Frost <sfrost@snowman.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephen Frost @ 2016-03-28 13:04 UTC (permalink / raw)
  To: pgsql-committers

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

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/86ebf30fd6d8964bbd5d48db053b0a7ff709a0d7

Modified Files
--------------
src/backend/utils/cache/plancache.c       | 41 ++++++++++++++++++++-----------
src/test/regress/expected/rowsecurity.out | 14 +++++++++++
src/test/regress/sql/rowsecurity.sql      |  9 +++++++
3 files changed, 49 insertions(+), 15 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Reset plan->row_security_env and planUserId
@ 2016-03-28 13:04  Stephen Frost <sfrost@snowman.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephen Frost @ 2016-03-28 13:04 UTC (permalink / raw)
  To: pgsql-committers

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

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/db69e58a0642ef7fa46d62f6c4cf2460c3a1b41b

Modified Files
--------------
src/backend/utils/cache/plancache.c       | 40 ++++++++++++++++++++-----------
src/test/regress/expected/rowsecurity.out | 14 +++++++++++
src/test/regress/sql/rowsecurity.sql      |  9 +++++++
3 files changed, 49 insertions(+), 14 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-03-28 13:04 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-28 13:04 pgsql: Reset plan->row_security_env and planUserId Stephen Frost <sfrost@snowman.net>
2016-03-28 13:04 pgsql: Reset plan->row_security_env and planUserId Stephen Frost <sfrost@snowman.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox