Skip to content

Commit 2ba9e2b

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 c0f0d80 commit 2ba9e2b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/backend/rewrite/rewriteHandler.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,8 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
17941794
{
17951795
if (hasSubLinks)
17961796
{
1797+
acquireLocksOnSubLinks_context context;
1798+
17971799
/*
17981800
* Recursively process the new quals, checking for infinite
17991801
* recursion.
@@ -1806,6 +1808,23 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
18061808

18071809
activeRIRs = lcons_oid(RelationGetRelid(rel), activeRIRs);
18081810

1811+
/*
1812+
* get_row_security_policies just passed back securityQuals
1813+
* and/or withCheckOptions, and there were SubLinks, make sure
1814+
* we lock any relations which are referenced.
1815+
*
1816+
* These locks would normally be acquired by the parser, but
1817+
* securityQuals and withCheckOptions are added post-parsing.
1818+
*/
1819+
context.for_execute = true;
1820+
(void) acquireLocksOnSubLinks((Node *) securityQuals, &context);
1821+
(void) acquireLocksOnSubLinks((Node *) withCheckOptions,
1822+
&context);
1823+
1824+
/*
1825+
* Now that we have the locks on anything added by
1826+
* get_row_security_policies, fire any RIR rules for them.
1827+
*/
18091828
expression_tree_walker((Node *) securityQuals,
18101829
fireRIRonSubLink, (void *) activeRIRs);
18111830

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy