From 4e51030af9e0a12d7fa06b73acd0c85024f81062 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 11 Nov 2024 09:00:00 -0600 Subject: Ensure cached plans are correctly marked as dependent on role. If a CTE, subquery, sublink, security invoker view, or coercion projection references a table with row-level security policies, 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. Reported-by: Wolfgang Walther Reviewed-by: Noah Misch Security: CVE-2024-10976 Backpatch-through: 12 --- src/backend/executor/functions.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/backend/executor/functions.c') diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index 2ec5c14ae6e..ed39c7abbda 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -1991,6 +1991,12 @@ tlist_coercion_finished: rtr->rtindex = 1; newquery->jointree = makeFromExpr(list_make1(rtr), NULL); + /* + * Make sure the new query is marked as having row security if the + * original one does. + */ + newquery->hasRowSecurity = parse->hasRowSecurity; + /* Replace original query in the correct element of the query list */ lfirst(parse_cell) = newquery; } -- cgit v1.2.3