pgsql: Reject pseudo-type output parameters in SQL functions.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reject pseudo-type output parameters in SQL functions.
Date: 2026-11-09 14:22:11
Message-ID: E1xQQGB-0000000044b-1EXW@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <pg(at)bowt(dot)ie>
Reported-by: Stephan Lipp <Stephan(at)Adalogics(dot)com>
Author: Peter Geoghegan <pg(at)bowt(dot)ie>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Security: CVE-2026-18447
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/046a36e03300b0f239dfb76801d3119568772c5d
Author: Peter Geoghegan <pg(at)bowt(dot)ie>

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:22:12 pgsql: Add tests for row type changes causing issues
Previous Message Noah Misch 2026-11-09 14:22:10 pgsql: Avoid visiting a type twice in find_composite_type_dependencies(