This is an automated email from the ASF dual-hosted git repository. yjhjstz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 6d20299b62c7a9d9cb769e14131dda22694ae7da Author: Tom Lane <t...@sss.pgh.pa.us> AuthorDate: Mon May 8 10:12:44 2023 -0400 Handle RLS dependencies in inlined set-returning functions properly. If an SRF in the FROM clause references a table having row-level security policies, and we inline that SRF into the calling query, we neglected to mark the plan as potentially dependent on which role is executing it. This could lead to later executions in the same session returning or hiding rows that should have been hidden or returned instead. Our thanks to Wolfgang Walther for reporting this problem. Stephen Frost and Tom Lane (cherry picked from commit ca73753b090c33bc69ce299b4d7fff891a77b8ad) NB: Greenplum did not have the problem described in the above commit message because it always aggressively evaluate stable functions. Refer to the following Greenplum commits for details: ccca0af2c6d3858b8a5a0659c40595d53bfe782c ce32a0dba1cb1435e839cfd9d9f1644ed214a0ed 4cf47434a35df73dd456b6648c5f40ee377b5845 we cherry-picked the upstream commit anyways only for test coverage and future-proofing purposes. --- src/backend/optimizer/util/clauses.c | 7 +++++++ src/test/regress/expected/rowsecurity.out | 27 +++++++++++++++++++++++++++ src/test/regress/sql/rowsecurity.sql | 20 ++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index b80ac211a9..433b8a2d71 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -5405,6 +5405,13 @@ inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte) */ record_plan_function_dependency(root, func_oid); + /* + * We must also notice if the inserted query adds a dependency on the + * calling role due to RLS quals. + */ + if (querytree->hasRowSecurity) + root->glob->dependsOnRole = true; + return querytree; /* Here if func is not inlinable: release temp memory and return NULL */ diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out index 3b9db328a4..15ee758b15 100644 --- a/src/test/regress/expected/rowsecurity.out +++ b/src/test/regress/expected/rowsecurity.out @@ -4167,6 +4167,33 @@ SELECT * FROM rls_tbl; DROP TABLE rls_tbl; RESET SESSION AUTHORIZATION; +-- CVE-2023-2455: inlining an SRF may introduce an RLS dependency +create table rls_t (c text); +insert into rls_t values ('invisible to bob'); +alter table rls_t enable row level security; +grant select on rls_t to regress_rls_alice, regress_rls_bob; +create policy p1 on rls_t for select to regress_rls_alice using (true); +create policy p2 on rls_t for select to regress_rls_bob using (false); +create function rls_f () returns setof rls_t + stable language sql + as $$ select * from rls_t $$; +prepare q as select current_user, * from rls_f(); +set role regress_rls_alice; +execute q; + current_user | c +-------------------+------------------ + regress_rls_alice | invisible to bob +(1 row) + +set role regress_rls_bob; +execute q; + current_user | c +--------------+--- +(0 rows) + +RESET ROLE; +DROP FUNCTION rls_f(); +DROP TABLE rls_t; -- -- Clean up objects -- diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql index 40b7f52a98..741a4bd5c5 100644 --- a/src/test/regress/sql/rowsecurity.sql +++ b/src/test/regress/sql/rowsecurity.sql @@ -1865,6 +1865,26 @@ SELECT * FROM rls_tbl; DROP TABLE rls_tbl; RESET SESSION AUTHORIZATION; +-- CVE-2023-2455: inlining an SRF may introduce an RLS dependency +create table rls_t (c text); +insert into rls_t values ('invisible to bob'); +alter table rls_t enable row level security; +grant select on rls_t to regress_rls_alice, regress_rls_bob; +create policy p1 on rls_t for select to regress_rls_alice using (true); +create policy p2 on rls_t for select to regress_rls_bob using (false); +create function rls_f () returns setof rls_t + stable language sql + as $$ select * from rls_t $$; +prepare q as select current_user, * from rls_f(); +set role regress_rls_alice; +execute q; +set role regress_rls_bob; +execute q; + +RESET ROLE; +DROP FUNCTION rls_f(); +DROP TABLE rls_t; + -- -- Clean up objects -- --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org For additional commands, e-mail: commits-h...@cloudberry.apache.org