Skip to content

Commit d03f331

Browse files
committed
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.
1 parent aed688e commit d03f331

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/backend/rewrite/rewriteHandler.c

+19
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,8 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
17871787
{
17881788
if (hasSubLinks)
17891789
{
1790+
acquireLocksOnSubLinks_context context;
1791+
17901792
/*
17911793
* Recursively process the new quals, checking for infinite
17921794
* recursion.
@@ -1799,6 +1801,23 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
17991801

18001802
activeRIRs = lcons_oid(RelationGetRelid(rel), activeRIRs);
18011803

1804+
/*
1805+
* get_row_security_policies just passed back securityQuals
1806+
* and/or withCheckOptions, and there were SubLinks, make sure
1807+
* we lock any relations which are referenced.
1808+
*
1809+
* These locks would normally be acquired by the parser, but
1810+
* securityQuals and withCheckOptions are added post-parsing.
1811+
*/
1812+
context.for_execute = true;
1813+
(void) acquireLocksOnSubLinks((Node *) securityQuals, &context);
1814+
(void) acquireLocksOnSubLinks((Node *) withCheckOptions,
1815+
&context);
1816+
1817+
/*
1818+
* Now that we have the locks on anything added by
1819+
* get_row_security_policies, fire any RIR rules for them.
1820+
*/
18021821
expression_tree_walker((Node *) securityQuals,
18031822
fireRIRonSubLink, (void *) activeRIRs);
18041823

0 commit comments

Comments
 (0)