Reject pseudo-type output parameters in SQL functions.

fmgr_sql_validator() rejected unsafe pseudo-type input parameters, but
neglected to apply the same rule to output parameters.  An SQL function
could therefore declare an output column of type "any".  This created
problems for tupledesc_match(), which checks an SQL function's result
rows against its declared output columns using IsBinaryCoercible().
IsBinaryCoercible accepts every type for "any", so rows of an arbitrary
row type could be read using a tuple descriptor that does not match
their physical layout.  This could be abused to disclose server memory
contents, and to perform arbitrary code execution.

To fix, teach fmgr_sql_validator() to apply its pseudo-type check to
parameters of every mode (not just for input parameters).

Note that the treatment of record is somewhat arbitrary: record and
record[] remain allowed as output column types, while record remains
disallowed as an input parameter type.  Allowing record in either
position is likely safe, but a back-patched security fix is not the
place to change existing behavior either way.

Reported-by: Peter Geoghegan <[email protected]>
Reported-by: Stephan Lipp <[email protected]>
Author: Peter Geoghegan <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Security: CVE-2026-18447
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ff961cbbf3af286665209b8039df3565ade198ae
Author: Peter Geoghegan <[email protected]>

Modified Files
--------------
src/backend/catalog/pg_proc.c                     | 36 +++++++++++-----
src/test/regress/expected/create_function_sql.out | 51 ++++++++++++++++++++++-
src/test/regress/sql/create_function_sql.sql      | 28 +++++++++++++
3 files changed, 103 insertions(+), 12 deletions(-)

Reply via email to