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:21:50
Message-ID: E1xQQFq-000000003M7-3zo1@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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c2439a04353ccab618006f21df8698aa9cc31167
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:21:51 pgsql: Close portals at end of trigger functions with transition tables
Previous Message Noah Misch 2026-11-09 14:21:49 pgsql: Reject more unsafe names in extension script substitutions.