Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca73753

Browse files
committed
Handle RLS dependencies in inlined set-returning functions properly.
If an SRF in the FROM clause references a table having row-levelsecurity policies, and we inline that SRF into the calling query,we neglected to mark the plan as potentially dependent on whichrole is executing it. This could lead to later executions in thesame session returning or hiding rows that should have been hiddenor returned instead.Our thanks to Wolfgang Walther for reporting this problem.Stephen Frost and Tom LaneSecurity:CVE-2023-2455
1 parent681d9e4 commitca73753

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

‎src/backend/optimizer/util/clauses.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5205,6 +5205,13 @@ inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
52055205
*/
52065206
record_plan_function_dependency(root,func_oid);
52075207

5208+
/*
5209+
* We must also notice if the inserted query adds a dependency on the
5210+
* calling role due to RLS quals.
5211+
*/
5212+
if (querytree->hasRowSecurity)
5213+
root->glob->dependsOnRole= true;
5214+
52085215
returnquerytree;
52095216

52105217
/* Here if func is not inlinable: release temp memory and return NULL */

‎src/test/regress/expected/rowsecurity.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,6 +4427,33 @@ SELECT * FROM rls_tbl;
44274427

44284428
DROP TABLE rls_tbl;
44294429
RESET SESSION AUTHORIZATION;
4430+
-- CVE-2023-2455: inlining an SRF may introduce an RLS dependency
4431+
create table rls_t (c text);
4432+
insert into rls_t values ('invisible to bob');
4433+
alter table rls_t enable row level security;
4434+
grant select on rls_t to regress_rls_alice, regress_rls_bob;
4435+
create policy p1 on rls_t for select to regress_rls_alice using (true);
4436+
create policy p2 on rls_t for select to regress_rls_bob using (false);
4437+
create function rls_f () returns setof rls_t
4438+
stable language sql
4439+
as $$ select * from rls_t $$;
4440+
prepare q as select current_user, * from rls_f();
4441+
set role regress_rls_alice;
4442+
execute q;
4443+
current_user | c
4444+
-------------------+------------------
4445+
regress_rls_alice | invisible to bob
4446+
(1 row)
4447+
4448+
set role regress_rls_bob;
4449+
execute q;
4450+
current_user | c
4451+
--------------+---
4452+
(0 rows)
4453+
4454+
RESET ROLE;
4455+
DROP FUNCTION rls_f();
4456+
DROP TABLE rls_t;
44304457
--
44314458
-- Clean up objects
44324459
--

‎src/test/regress/sql/rowsecurity.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,26 @@ SELECT * FROM rls_tbl;
21272127
DROPTABLE rls_tbl;
21282128
RESET SESSION AUTHORIZATION;
21292129

2130+
-- CVE-2023-2455: inlining an SRF may introduce an RLS dependency
2131+
createtablerls_t (ctext);
2132+
insert into rls_tvalues ('invisible to bob');
2133+
altertable rls_t enable row level security;
2134+
grantselecton rls_t to regress_rls_alice, regress_rls_bob;
2135+
create policy p1on rls_t forselect to regress_rls_alice using (true);
2136+
create policy p2on rls_t forselect to regress_rls_bob using (false);
2137+
createfunctionrls_f () returns setof rls_t
2138+
stable language sql
2139+
as $$select*from rls_t $$;
2140+
prepare qasselectcurrent_user,*from rls_f();
2141+
set role regress_rls_alice;
2142+
execute q;
2143+
set role regress_rls_bob;
2144+
execute q;
2145+
2146+
RESET ROLE;
2147+
DROPFUNCTION rls_f();
2148+
DROPTABLE rls_t;
2149+
21302150
--
21312151
-- Clean up objects
21322152
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp