pgsql: Teach equalRowTypes() to safely handle dropped columns.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Teach equalRowTypes() to safely handle dropped columns.
Date: 2026-11-09 14:22:00
Message-ID: E1xQQG0-000000003gf-27Hv@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Teach equalRowTypes() to safely handle dropped columns.

equalRowTypes compared the name, type, typmod, and collation of
corresponding attributes. That's sufficient when neither attribute has
been dropped, since their physical storage attributes (attlen and
attalign) are derived from their type. But a dropped attribute has its
atttypid set to InvalidOid while keeping the attlen and attalign of the
type that the column used to have. Two row types that merely had
dropped attributes in the same positions could therefore be considered
equal, even when the dropped attributes' widths or alignments differed.

That was a problem for typcache.c's record type cache, which relies on
equalRowTypes to decide whether a tuple descriptor matches one that was
already assigned a record typmod. A tuple built using one tuple
descriptor could be assigned the typmod of a physically incompatible
descriptor, allowing it to be deformed using that descriptor. That
could be abused to make the server disclose memory contents, and to
achieve arbitrary code execution.

To fix, make equalRowTypes also compare the attlen and attalign of
corresponding dropped attributes.

Oversight in commit 20e58105, which introduced equalRowTypes.
equalTupleDescs already compared attlen and attalign, but equalRowTypes
missed that precedent.

Reported-by: Peter Geoghegan <pg(at)bowt(dot)ie>
Author: Peter Geoghegan <pg(at)bowt(dot)ie>
Reviewed-by: Robert Haas <robertmhaas(at)gmail(dot)com>
Reviewed-by: Andrew Dunstan <andrew(at)dunslane(dot)net>
Security: CVE-2026-120142
Backpatch-through: 17

Branch
------
REL_18_STABLE

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

Modified Files
--------------
src/backend/access/common/tupdesc.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:22:01 pgsql: Introduce attribute versioning to prevent unsafe deforming
Previous Message Noah Misch 2026-11-09 14:21:59 pgsql: Reject pseudo-types in extended statistics expressions.