aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2015-08-28 11:39:37 -0400
committerStephen Frost <sfrost@snowman.net>2015-08-28 11:39:37 -0400
commit2ba9e2b778af7a8d040283db6cee11fb03cf9f4a (patch)
treed6ed8254abb2cb191a2acd0019120d5c651182f4 /src
parentc0f0d8097be17ae7f03fc79f622e9c95026b338a (diff)
downloadpostgresql-2ba9e2b778af7a8d040283db6cee11fb03cf9f4a.tar.gz
postgresql-2ba9e2b778af7a8d040283db6cee11fb03cf9f4a.zip
Ensure locks are acquired on RLS-added relations
During fireRIRrules(), get_row_security_policies can add to securityQuals and withCheckOptions. Make sure to lock any relations added at that point and before firing RIR rules on those expressions. Back-patch to 9.5 where RLS was added.
Diffstat (limited to 'src')
-rw-r--r--src/backend/rewrite/rewriteHandler.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 5cf9cc7bccc..761047ca082 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -1794,6 +1794,8 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
{
if (hasSubLinks)
{
+ acquireLocksOnSubLinks_context context;
+
/*
* Recursively process the new quals, checking for infinite
* recursion.
@@ -1806,6 +1808,23 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
activeRIRs = lcons_oid(RelationGetRelid(rel), activeRIRs);
+ /*
+ * get_row_security_policies just passed back securityQuals
+ * and/or withCheckOptions, and there were SubLinks, make sure
+ * we lock any relations which are referenced.
+ *
+ * These locks would normally be acquired by the parser, but
+ * securityQuals and withCheckOptions are added post-parsing.
+ */
+ context.for_execute = true;
+ (void) acquireLocksOnSubLinks((Node *) securityQuals, &context);
+ (void) acquireLocksOnSubLinks((Node *) withCheckOptions,
+ &context);
+
+ /*
+ * Now that we have the locks on anything added by
+ * get_row_security_policies, fire any RIR rules for them.
+ */
expression_tree_walker((Node *) securityQuals,
fireRIRonSubLink, (void *) activeRIRs);