mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Make relation-enumerating operations be security-restricted operations.
When a feature enumerates relations and runs functions associated with all found relations, the feature's user shall not need to trust every user having permission to create objects. BRIN-specific functionality in autovacuum neglected to account for this, as did pg_amcheck and CLUSTER. An attacker having permission to create non-temp objects in at least one schema could execute arbitrary SQL functions under the identity of the bootstrap superuser. CREATE INDEX (not a relation-enumerating operation) and REINDEX protected themselves too late. This change extends to the non-enumerating amcheck interface. Back-patch to v10 (all supported versions). Sergey Shinderuk, reviewed (in earlier versions) by Alexander Lakhin. Reported by Alexander Lakhin. Security: CVE-2022-1552
This commit is contained in:
@ -115,11 +115,32 @@ INSERT INTO toast_bug SELECT repeat('a', 2200);
|
||||
-- Should not get false positive report of corruption:
|
||||
SELECT bt_index_check('toasty', true);
|
||||
|
||||
--
|
||||
-- Check that index expressions and predicates are run as the table's owner
|
||||
--
|
||||
TRUNCATE bttest_a;
|
||||
INSERT INTO bttest_a SELECT * FROM generate_series(1, 1000);
|
||||
ALTER TABLE bttest_a OWNER TO regress_bttest_role;
|
||||
-- A dummy index function checking current_user
|
||||
CREATE FUNCTION ifun(int8) RETURNS int8 AS $$
|
||||
BEGIN
|
||||
ASSERT current_user = 'regress_bttest_role',
|
||||
format('ifun(%s) called by %s', $1, current_user);
|
||||
RETURN $1;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql IMMUTABLE;
|
||||
|
||||
CREATE INDEX bttest_a_expr_idx ON bttest_a ((ifun(id) + ifun(0)))
|
||||
WHERE ifun(id + 10) > ifun(10);
|
||||
|
||||
SELECT bt_index_check('bttest_a_expr_idx', true);
|
||||
|
||||
-- cleanup
|
||||
DROP TABLE bttest_a;
|
||||
DROP TABLE bttest_b;
|
||||
DROP TABLE bttest_multi;
|
||||
DROP TABLE delete_test_table;
|
||||
DROP TABLE toast_bug;
|
||||
DROP FUNCTION ifun(int8);
|
||||
DROP OWNED BY regress_bttest_role; -- permissions
|
||||
DROP ROLE regress_bttest_role;
|
||||
|
Reference in New Issue
Block a user