RI fastpath misses checking EXECUTE on functions

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: rmt(at)lists(dot)postgresql(dot)org
Subject: RI fastpath misses checking EXECUTE on functions
Date: 2026-09-24 03:42:34
Message-ID: CA+HiwqGH+b7sXmsH8sT18diujbheSObWs0gWXqLZqRccMKvZAA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

It was pointed out to me offlist by Nikolay Samokhvalov that the RI
fast path (ri_FastPathCheck) doesn't check EXECUTE privilege on the
functions it invokes on the FK values. There are two such functions:
the equality operator's function, which goes into the ScanKey the
index AM evaluates, and the implicit cast function, which is used when
the FK value must be converted to the PK column's type. In the SPI
path's case, because the operator appears in the generated query's
WHERE clause and the cast as $1::pktype, ExecutorStart checked EXECUTE
on both as part of initializing the query, as the referenced table's
owner. So while I added ri_CheckPermissions() to parallel the
executor's ExecCheckPermissions(), I missed the non-relation
permission checks that occur as part of expression initialization.

The attached patch adds ri_CheckFunctionPermissions(), which does
object_aclcheck(ProcedureRelationId, ..., ACL_EXECUTE) plus
InvokeFunctionExecuteHook() for each of the two functions, and calls
it once the fast-path metadata is populated. That puts the checks at
the same point as the existing relation permission check.

Regression tests are included for both functions. They reach the fast
path through per-row validation of a new constraint, and repeat each
case against a partitioned referenced table, which takes the SPI path,
to establish that the two behave identically.

I'll add an open item. I would like to get this committed by EOW if
there are no comments.

--
Thanks, Amit Langote

Attachment Content-Type Size
v1-0001-Check-EXECUTE-privilege-on-functions-invoked-by-t.patch application/octet-stream 13.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-09-24 03:49:30 Re: Persist slot invalidations before publishing them
Previous Message Grigorev Jurij 2026-09-24 03:39:10 Re: DSA_ALLOC_NO_OOM vs dsm_create ERROR leaving a half-initialized pgstats hash entry