Re: Prevent object capture in CREATE/ALTER EXTENSION scripts
Re: Prevent object capture in CREATE/ALTER EXTENSION scripts
От:
solai v <solai.cdac@gmail.com>
Дата:
Hi all,
I tested the latest patch series for preventing object capture in
CREATE/ALTER EXTENSION scripts.
First, I was able to reproduce the reported issue. With f(varchar)
owned by the trusted role and an attacker-owned f(text) in the same
schema, the call f('abc') from the extension script resolved to the
attacker-owned function and returned ATTACKER FUNCTION.
I then tested patch 0001 alone. The behavior was unchanged, and the
extension script still resolved the call to ATTACKER FUNCTION.
After applying both patches, I repeated the test with the varchar
function owned by a superuser and the text function owned by a
non-superuser. This time, the extension was created successfully and
the result was:
SELECT * FROM test_ext.capture_result;
TRUSTED FUNCTION
I also checked the normal function calls outside the extension script:
f('abc'::varchar) -> TRUSTED FUNCTION
f('abc'::text) -> ATTACKER FUNCTION
f('abc') ->ATTACKER FUNCTION
So the normal function resolution behavior remains unchanged.
The regression tests added by the patch also passed successfully:
Overall, the patch worked as expected in my testing. The extension
script now selects the trusted candidate instead of the attacker-owned
candidate when both overloads are present.
Regards,
solai
Re: Prevent object capture in CREATE/ALTER EXTENSION scripts
Hi solai, On 22.09.26 06:13, solai v wrote: [...] > Overall, the patch worked as expected in my testing. The extension > script now selects the trusted candidate instead of the attacker-owned > candidate when both overloads are present. Thank you so much for the review. While testing the patch further, I found a gap with schema-qualified names. In v1, the trust check for relations and types was applied only when the script used an unqualified name and the lookup went through RelnameGetRelid() or TypenameGetTypidExtended(). A reference such as @extschema@.foo took the qualified branch of RangeVarGetRelidExtended() or LookupTypeNameExtended() and was not checked at all. Functions and operators were not affected, since their candidate lookup handles both versions in one place. v2 adds the check to those two branches, so an untrusted match is treated as nonexistent there too. I also added tests for this case; I slightly adjusted the commit message and rebased the patch set against master. Best regards Jan -- Jan Nidzwetzki PlanetScale Postgres Core Team
Re: Prevent object capture in CREATE/ALTER EXTENSION scripts
От:
Jan Nidzwetzki <jan@planetscale.com>
Дата:
Hi Hackers, To confirm the patch works with existing extensions, I ran additional tests. I installed various extensions on both a patched and an unpatched server. I tested contrib and src/test/modules on master (95 extensions), and all postgresql-18-* packages from apt.postgresql.org plus contrib (171 extensions) on a backport of this patch to 18.6 (since there are no extension packages for master). I installed each extension as a superuser and, when possible (trusted or superuser = false), also as a non-superuser. I also did this in databases that already had objects owned by a non-superuser. I updated extensions from older versions to the current one and repeated the installs with debug_parallel_query set to regress. Only a few scripts actually ran queries in parallel workers, and they behaved the same on both servers. For each run, I compared the results of every statement and checked which objects the extension's members pointed to using pg_depend. I found no differences between the patched and unpatched servers. The regression tests for contrib and 35 third-party extensions also gave the same results. For the third-party regression tests, I only included extensions that run their tests with a plain PGXS "make installcheck". I'm happy to share the scripts I used if anyone wants to rerun the tests. Best regards Jan -- Jan Nidzwetzki PlanetScale