- Notifications
You must be signed in to change notification settings - Fork5.2k
Commit7e86da5
committed
Fix security checks in selectivity estimation functions.
Commite2d4ef8 (the fix forCVE-2017-7484) added security checksto the selectivity estimation functions to prevent them from runninguser-supplied operators on data obtained from pg_statistic if the userlacks privileges to select from the underlying table. In casesinvolving inheritance/partitioning, those checks were originallyperformed against the child RTE (which for plain inheritance mightactually refer to the parent table). Commit553d2ec then extendedthat to also check the parent RTE, allowing access if the user hadpermissions on either the parent or the child. It turns out, however,that doing any checks using the child RTE is incorrect, sincesecurityQuals is set to NULL when creating an RTE for an inheritancechild (whether it refers to the parent table or the child table), andtherefore such checks do not correctly account for any RLS policies orsecurity barrier views. Therefore, do the security checks using onlythe parent RTE. This is consistent with how RLS policies are applied,and the executor's ACL checks, both of which use only the parenttable's permissions/policies. Similar checks are performed in theextended stats code, so update that in the same way, centralizing allthe checks in a new function.In addition, note that these checks by themselves are insufficient toensure that the user has access to the table's data because, in aquery that goes via a view, they only check that the view owner haspermissions on the underlying table, not that the current user haspermissions on the view itself. In the selectivity estimationfunctions, there is no easy way to navigate from underlying tables toviews, so add permissions checks for all views mentioned in the queryto the planner startup code. If the user lacks permissions on a view,a permissions error will now be reported at planner-startup, and theselectivity estimation functions will not be run.Checking view permissions at planner-startup in this way is a littleugly, since the same checks will be repeated at executor-startup.Longer-term, it might be better to move all the permissions checksfrom the executor to the planner so that permissions errors can bereported 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 addedcomplication that UPDATEs and DELETEs on inherited target tables areplanned using inheritance_planner(), which plans each inheritancechild table separately, so that the selectivity estimation functionsdo not know that they are dealing with a child table accessed via itsparent. Handle that by checking access permissions on the top parenttable at planner-startup, in the same way as we do for views. AnysecurityQuals on the top parent table are moved down to the childtables by inheritance_planner(), so they continue to be checked by theselectivity estimation functions.Author: Dean Rasheed <dean.a.rasheed@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Noah Misch <noah@leadboat.com>Backpatch-through: 13Security:CVE-2025-87131 parent94c0673 commit7e86da5
File tree
12 files changed
+569
-288
lines changed- src
- backend
- executor
- optimizer/plan
- statistics
- utils/adt
- include
- executor
- utils
- test/regress
- expected
- sql
12 files changed
+569
-288
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
| |||
635 | 634 | | |
636 | 635 | | |
637 | 636 | | |
638 | | - | |
| 637 | + | |
639 | 638 | | |
640 | 639 | | |
641 | 640 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
788 | 789 | | |
789 | 790 | | |
790 | 791 | | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
791 | 824 | | |
792 | 825 | | |
793 | 826 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1344 | 1344 | | |
1345 | 1345 | | |
1346 | 1346 | | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
1347 | 1350 | | |
1348 | 1351 | | |
1349 | 1352 | | |
1350 | 1353 | | |
1351 | 1354 | | |
1352 | 1355 | | |
1353 | 1356 | | |
1354 | | - | |
| 1357 | + | |
1355 | 1358 | | |
1356 | 1359 | | |
1357 | 1360 | | |
| |||
1386 | 1389 | | |
1387 | 1390 | | |
1388 | 1391 | | |
1389 | | - | |
1390 | 1392 | | |
1391 | 1393 | | |
1392 | 1394 | | |
| |||
1421 | 1423 | | |
1422 | 1424 | | |
1423 | 1425 | | |
1424 | | - | |
1425 | | - | |
1426 | | - | |
1427 | | - | |
1428 | | - | |
1429 | | - | |
1430 | | - | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | | - | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
1437 | 1429 | | |
1438 | 1430 | | |
1439 | 1431 | | |
1440 | 1432 | | |
1441 | | - | |
| 1433 | + | |
| 1434 | + | |
1442 | 1435 | | |
1443 | 1436 | | |
1444 | 1437 | | |
| |||
1448 | 1441 | | |
1449 | 1442 | | |
1450 | 1443 | | |
1451 | | - | |
1452 | 1444 | | |
1453 | 1445 | | |
1454 | 1446 | | |
| |||
1488 | 1480 | | |
1489 | 1481 | | |
1490 | 1482 | | |
1491 | | - | |
1492 | | - | |
1493 | | - | |
1494 | | - | |
1495 | | - | |
1496 | | - | |
1497 | | - | |
1498 | | - | |
1499 | | - | |
1500 | | - | |
1501 | | - | |
1502 | | - | |
1503 | | - | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
1504 | 1486 | | |
1505 | 1487 | | |
1506 | 1488 | | |
1507 | 1489 | | |
1508 | | - | |
| 1490 | + | |
| 1491 | + | |
1509 | 1492 | | |
1510 | 1493 | | |
1511 | 1494 | | |
| |||
1542 | 1525 | | |
1543 | 1526 | | |
1544 | 1527 | | |
1545 | | - | |
| 1528 | + | |
| 1529 | + | |
1546 | 1530 | | |
1547 | 1531 | | |
1548 | 1532 | | |
| |||
1556 | 1540 | | |
1557 | 1541 | | |
1558 | 1542 | | |
1559 | | - | |
1560 | | - | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
1561 | 1547 | | |
1562 | 1548 | | |
1563 | 1549 | | |
| |||
1596 | 1582 | | |
1597 | 1583 | | |
1598 | 1584 | | |
1599 | | - | |
1600 | | - | |
1601 | 1585 | | |
1602 | 1586 | | |
1603 | | - | |
| 1587 | + | |
1604 | 1588 | | |
1605 | 1589 | | |
1606 | 1590 | | |
| |||
1640 | 1624 | | |
1641 | 1625 | | |
1642 | 1626 | | |
1643 | | - | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
1644 | 1632 | | |
1645 | | - | |
| 1633 | + | |
| 1634 | + | |
1646 | 1635 | | |
1647 | 1636 | | |
1648 | 1637 | | |
1649 | | - | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
1650 | 1650 | | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | | - | |
| 1651 | + | |
1655 | 1652 | | |
1656 | 1653 | | |
1657 | 1654 | | |
| |||
1676 | 1673 | | |
1677 | 1674 | | |
1678 | 1675 | | |
1679 | | - | |
1680 | | - | |
1681 | | - | |
1682 | | - | |
1683 | | - | |
1684 | | - | |
1685 | | - | |
1686 | | - | |
1687 | | - | |
1688 | | - | |
1689 | | - | |
1690 | | - | |
1691 | | - | |
1692 | | - | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
1699 | 1679 | | |
1700 | 1680 | | |
1701 | 1681 | | |
| |||
0 commit comments
Comments
(0)