Automated Threat Modeling

Overview of CVE-2026-120142: PostgreSQL Anonymous RECORD Type Confusion Enables Code Execution

A brief summary of CVE-2026-120142, a type confusion flaw in how PostgreSQL 17 and 18 handle anonymous RECORD types. It lets an object creator run arbitrary code as the database OS user. Includes root cause and patch information for the fixed 17.12 and 18.7 releases.

CVE Analysis

7 min read

Gaurav Sarraf
Gaurav Sarraf

2026-11-12

Overview of CVE-2026-120142: PostgreSQL Anonymous RECORD Type Confusion Enables Code Execution

Introduction

A database user who is allowed to create objects could turn a small omission in PostgreSQL's row type comparison logic into arbitrary code execution as the operating system user running the database server. That moves the impact of a low-privileged account well past the SQL permission model. It matters most for PostgreSQL 17 and 18 deployments where application or tenant roles are permitted to create tables and types.

The flaw, tracked as CVE-2026-120142, was fixed in PostgreSQL 18.7 and 17.12 on November 12, 2026. Below we summarize the root cause from the fix commit, the patch itself, and the exact affected versions.

Technical information

FieldValue
CVECVE-2026-120142
WeaknessCWE-843, Access of Resource Using Incompatible Type (type confusion)
CVSS8.8 High (CVSS 3.0 in the PostgreSQL advisory; CNA CVSS 3.1 on NVD)
VectorAV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
ImpactArbitrary code execution as the OS user running PostgreSQL
Required positionObject creator (low privileges, no user interaction)

NVD notes that it has not yet provided its own assessment. The 8.8 score comes from the CNA and the PostgreSQL advisory.

What equalRowTypes() is supposed to do

equalRowTypes() in src/backend/access/common/tupdesc.c decides whether two tuple descriptors describe the same row type. Its header comment says it is used to check whether two record types are compatible, whether function return row types are the same, and similar situations.

Before the fix, the function compared each pair of attributes by:

  • name
  • type OID (atttypid)
  • typmod
  • collation
  • whether both are dropped or both are live (attisdropped)

For live columns this is enough. The physical layout of a column, its byte width (attlen) and its alignment (attalign), follows directly from its type, so matching type OIDs implies matching layouts.

Why dropped columns break that assumption

When a column is dropped, PostgreSQL sets its atttypid to InvalidOid. The bytes for that column still exist in tuples written before the drop, so the dropped attribute has to keep the attlen and attalign of its original type for tuple decoding to work.

That creates a gap. Two row types with a dropped column in the same position both report InvalidOid for that attribute, so equalRowTypes() saw them as identical, even if one dropped column had originally been a 4-byte int4 and the other an 8-byte, double-aligned float8. For dropped attributes, the type OID comparison that normally guarantees layout compatibility carried no information.

Where the confusion happens: the anonymous RECORD cache

According to the fix commit message, the consequence shows up in typcache.c, which keeps a cache of anonymous RECORD types. When a new tuple descriptor needs a record typmod, the cache uses equalRowTypes() to decide whether the descriptor matches one that already has a typmod assigned.

With the flawed comparison, a descriptor whose dropped column had one width or alignment could be matched to a cached descriptor whose dropped column had another. A tuple built with the first descriptor would then carry the typmod of the second and be decoded using the wrong layout. Every attribute after the mismatched dropped column would be read at the wrong offset. That misread is the type confusion, and the commit message states it could be abused to leak memory and to achieve arbitrary code execution.

Origin of the bug

The commit traces the regression to commit 20e58105, which introduced equalRowTypes(). Its sibling function equalTupleDescs() already compared attlen and attalign, but the new function did not carry that check over. This is consistent with the advisory's statement that versions before PostgreSQL 17 were never affected.

Attack flow

Based on the advisory and the commit message, exploitation follows this general shape. The sources do not publish a working exploit, so the details of turning a misread into code execution are not public.

  1. The attacker holds a role that can create objects in the database (the advisory's "object creator", rated as low privileges in the CVSS vector).
  2. The attacker sets up row types that have dropped attributes in the same positions, where the original types of those dropped columns differ in width or alignment.
  3. The anonymous RECORD type cache in typcache.c compares the descriptors with equalRowTypes(), treats them as equal, and assigns a tuple the typmod of the physically different descriptor.
  4. PostgreSQL decodes that tuple using the wrong layout, reading fields at incorrect offsets.
  5. According to the commit, this confusion can be used to leak memory and to execute arbitrary code as the operating system user that runs PostgreSQL.

Patch information

The fix is a single small commit by Peter Geoghegan, committed by Noah Misch and reviewed by Robert Haas and Andrew Dunstan. Its title is "Teach equalRowTypes() to safely handle dropped columns." The release notes describe it as "Handle dropped columns safely while comparing row types". It was backpatched to both affected branches:

BranchFix commitShipped in
REL_18_STABLE35d851811f9f2ebb8d88baa27964bce8fb98ef4018.7
REL_17_STABLE354d5c71b1257da60f3186367c0b4c6f1d9cb69217.12

Each branch commit adds 15 lines to one file, src/backend/access/common/tupdesc.c, and deletes nothing. The function header comment gains a new compatibility rule:

* - corresponding dropped attributes have the same width and alignment * (needed because no other test reliably detects pairs of dropped * attributes whose types would otherwise make tuple deformation unsafe)

The per-attribute loop in equalRowTypes() gains the new check. This is the REL_18_STABLE version. REL_17_STABLE is identical at different line offsets:

/* Record types derived from tables could have dropped fields. */ if (attr1->attisdropped != attr2->attisdropped) return false; /* * Dropped fields could have incompatible lengths/alignments (can't * rely on atttypid for this) */ if (attr1->attisdropped) { if (attr1->attlen != attr2->attlen) return false; if (attr1->attalign != attr2->attalign) return false; } } return true;

Why this closes the hole

The existing attisdropped inequality check already guarantees that both attributes are dropped or both are live. So the new if (attr1->attisdropped) block only runs when both are dropped, which is precisely the case where atttypid is InvalidOid and says nothing about layout.

In that case the function now compares the two values that actually govern tuple decoding: attlen (the byte width, or a variable-length marker of negative one or negative two) and attalign (the padding before the field). If either differs, equalRowTypes() returns false, the record type cache treats the descriptors as distinct, and they receive separate typmods. A tuple can no longer be decoded with a descriptor whose dropped column layout does not match its own bytes.

Operational impact of the fix

The change is narrow. It only adds a reason to declare two row types unequal:

  • Row types without dropped columns are compared exactly as before.
  • Matching dropped columns with the same width and alignment still compare equal, so normal record type sharing keeps working.
  • No on-disk format, catalog or API changes are involved.

The PostgreSQL release announcement states that a dump and reload or pg_upgrade is not required for a minor release update: stop PostgreSQL and update its binaries. The same announcement also ships 16.16, 15.20 and 14.25, but this CVE affects only the 17 and 18 branches.

Affected systems and versions

Major versionAffectedFixed in
PostgreSQL 18All minor versions before 18.718.7
PostgreSQL 17All minor versions before 17.1217.12
PostgreSQL 16 and earlierNot affectedNot applicable

The vulnerable configuration is any affected 17 or 18 server where an attacker controls a role able to create objects. The advisory does not describe further configuration prerequisites.

Vendor security history

The PostgreSQL Global Development Group publishes per-CVE security advisories and delivers security fixes through minor releases. Its versioning policy states that each major version receives bug fixes and, if needed, security fixes in minor releases at least once every three months, and the project's security page advises running the latest minor version. For context on the size of this cycle, the November 12, 2026 announcement covering 18.7, 17.12, 16.16, 15.20 and 14.25 fixed 52 security vulnerabilities and more than 140 bugs across all branches. That figure covers the whole release, not this CVE alone.

Exploitation in the wild is not confirmed in the sources we reviewed, and no threat actor, campaign or public exploit has been tied to this CVE. That should be read as an information gap rather than evidence of no exploitation.

References

Detect & fix
what others miss

Works with
  • GitHub
  • GitLab
  • Bitbucket
  • Azure DevOps Services
  • Gerrit
  • CVS
  • Jira
  • Linear
  • Slack
  • Security Compass
Explore integrations
Security magnifying glass visualization