reshke opened a new pull request, #1562:
URL: https://github.com/apache/cloudberry/pull/1562

   …tions.
   
   origin commit:
   
https://git.postgresql.org/cgit/postgresql.git/commit/?id=afe38fb6abb8ef364191201f577a5a638ba55509
   
   
   ====
   
   Commit e2d4ef8de86 (the fix for CVE-2017-7484) added security checks to the 
selectivity estimation functions to prevent them from running user-supplied 
operators on data obtained from pg_statistic if the user lacks privileges to 
select from the underlying table. In cases involving inheritance/partitioning, 
those checks were originally performed against the child RTE (which for plain 
inheritance might actually refer to the parent table). Commit 553d2ec2710 then 
extended that to also check the parent RTE, allowing access if the user had 
permissions on either the parent or the child. It turns out, however, that 
doing any checks using the child RTE is incorrect, since securityQuals is set 
to NULL when creating an RTE for an inheritance child (whether it refers to the 
parent table or the child table), and therefore such checks do not correctly 
account for any RLS policies or security barrier views. Therefore, do the 
security checks using only the parent RTE. This is consistent with how
  RLS policies are applied, and the executor's ACL checks, both of which use 
only the parent table's permissions/policies. Similar checks are performed in 
the extended stats code, so update that in the same way, centralizing all the 
checks in a new function.
   
   In addition, note that these checks by themselves are insufficient to ensure 
that the user has access to the table's data because, in a query that goes via 
a view, they only check that the view owner has permissions on the underlying 
table, not that the current user has permissions on the view itself. In the 
selectivity estimation functions, there is no easy way to navigate from 
underlying tables to views, so add permissions checks for all views mentioned 
in the query to the planner startup code. If the user lacks permissions on a 
view, a permissions error will now be reported at planner-startup, and the 
selectivity estimation functions will not be run.
   
   Checking view permissions at planner-startup in this way is a little ugly, 
since the same checks will be repeated at executor-startup. Longer-term, it 
might be better to move all the permissions checks from the executor to the 
planner so that permissions errors can be reported sooner, instead of creating 
a plan that won't ever be run. However, such a change seems too far-reaching to 
be back-patched.
   
   Back-patch to all supported versions. In v13, there is the added 
complication that UPDATEs and DELETEs on inherited target tables are planned 
using inheritance_planner(), which plans each inheritance child table 
separately, so that the selectivity estimation functions do not know that they 
are dealing with a child table accessed via its parent. Handle that by checking 
access permissions on the top parent table at planner-startup, in the same way 
as we do for views. Any securityQuals on the top parent table are moved down to 
the child tables by inheritance_planner(), so they continue to be checked by 
the selectivity estimation functions.
   
   Author: Dean Rasheed <[email protected]>
   Reviewed-by: Tom Lane <[email protected]>
   Reviewed-by: Noah Misch <[email protected]>
   Backpatch-through: 13
   Security: CVE-2025-8713
   
   <!-- Thank you for your contribution to Apache Cloudberry (Incubating)! -->
   
   Fixes #ISSUE_Number
   
   ### What does this PR do?
   <!-- Brief overview of the changes, including any major features or fixes -->
   
   ### Type of Change
   - [ ] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Breaking Changes
   <!-- Remove if not applicable. If yes, explain impact and migration path -->
   
   ### Test Plan
   <!-- How did you test these changes? -->
   - [ ] Unit tests added/updated
   - [ ] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   ### Impact
   <!-- Remove sections that don't apply -->
   **Performance:**
   <!-- Any performance implications? -->
   
   **User-facing changes:**
   <!-- Any changes visible to users? -->
   
   **Dependencies:**
   <!-- New dependencies or version changes? -->
   
   ### Checklist
   - [ ] Followed [contribution 
guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [ ] Reviewed code for security implications
   - [ ] Requested review from [cloudberry 
committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   <!-- Any other information that would help reviewers? Remove if none -->
   
   ### CI Skip Instructions
   <!--
   To skip CI builds, add the appropriate CI skip identifier to your PR title.
   The identifier must:
   - Be in square brackets []
   - Include the word "ci" and either "skip" or "no"
   - Only use for documentation-only changes or when absolutely necessary
   -->
   
   ---
   <!-- Join our community:
   - Mailing list: 
[[email protected]](https://lists.apache.org/[email protected])
 (subscribe: [email protected])
   - Discussions: https://github.com/apache/cloudberry/discussions -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to