Inside CVE-2026-6460: how PostgreSQL started versioning its composite types

The fix for CVE-2026-6460 spans 28 commits and a new layer in PostgreSQL's core. How the flaw works, how the fix works, and what changes for whoever runs the database.

Capa com o código CVE-2026-6460, a nota CVSS 8.8 e as versões corrigidas ao lado de uma pilha de discos de banco de dados com uma camada em vermelho
Uma camada nova no core, debaixo das proteções que já existiam.

CVE-2026-6460 came out on November 12, 2026 with a short description: a type confusion in PostgreSQL's core lets an object creator run code as the operating system user running the server. CVSS 8.8, low privilege, no workaround.

The alert version of this article covers what you need to decide and update. This one goes inside: what exactly was wrong, why the existing protections weren't enough, how the fix works and, above all, what changes in day-to-day operations after the upgrade. Everything here comes from official sources: the advisory, the release notes and the fix commits themselves.

The problem in one sentence

A composite-type value can be read with a different "mold" than the one it was written with.

In PostgreSQL, a composite type is a structure with fields, like a table row. Every table has an associated composite type, and stand-alone ones can be created with CREATE TYPE ... AS (...). A value of that type is stored as a sequence of bytes, and to read the fields the server uses a tuple descriptor: the list of fields, types, sizes and alignments. The fix's design document calls that reading deforming.

If the descriptor used to read doesn't match the layout the value was formed with, the server interprets bytes in the wrong place. In the project's own words, this "can lead to crashes, spurious errors and in some circumstances can be used to achieve arbitrary code execution".

Two-row diagram. Before the fix: a composite value is formed with the type at version 1, an ALTER changes the type and the read uses the new descriptor, interpreting bytes in the wrong place. After the fix: the value is stamped with the type version, the ALTER bumps the attribute version and the read compares versions, raising an error on mismatch
Before, reads trusted the catalog. Now, the value carries the version of the type that formed it.

Why an ALTER can cause this

The design document that ships with the fix (src/backend/catalog/README.attver.md) separates two cases:

  • Anonymous records (the record type, created by ROW(), subqueries or functions returning record) have their definition frozen when they are created. It can't change later.
  • Named composite types (those of tables, views, and those made with CREATE TYPE) can change through ALTER TYPE ... ADD | DROP | ALTER ATTRIBUTE or ALTER TABLE ... ADD | DROP | ALTER COLUMN.

The risk is in the second case: the catalog definition can change between the moment a value is created and the moment it is read. The advisory names the main route, ALTER ... SET DATA TYPE, and another DDL route: ALTER TABLE ... ADD COLUMN; ROLLBACK; ALTER TABLE ... ADD COLUMN.

The ROLLBACK detail is the subtlest. Per the design document, an attribute added in a transaction that is later rolled back can share its number with an attribute added afterwards, with another type. Outside that case, attribute numbers are never reused. Values formed inside the rolled-back transaction can survive the rollback and later be read with the new attribute.

Why the old protections weren't enough

PostgreSQL already defended against changing a type in use. The design document lists three defenses:

ProtectionWhat it guarantees
A table can't be altered while in use in the same session (CheckTableNotInUse())The session itself doesn't change a table under a running query
Tables are locked when accessed, and the descriptor is built with the lock heldWhen reading table rows, the descriptor is always compatible
Columns of composite types can't be altered if the type is used in other objects (find_composite_type_dependencies())A type used in another table's column can't change

Then the sentence that sums up the problem: none of these mechanisms prevents altering the type while transient objects, like prepared statements or cursors, hold composite values. PL/pgSQL variables, open cursors, in-memory values during execution: all of that sits outside lock-based protection.

The release notes add that the existing checks "were never really complete" and "entirely failed to detect" composite types changed concurrently with queries using them.

The design document admits it: it is "surprisingly easy" to introduce new paths that violate type safety.

The fix in three layers

The set has 28 commits in the official repository tagged with the CVE: 13 by Andres Freund and 15 by Heikki Linnakangas. They fall into three fronts.

1. Attribute versioning: a safety net at the bottom

The central commit, Introduce attribute versioning to prevent unsafe deforming (Andres Freund), adds a layer below the existing protections. The idea: every named composite value now carries the version of the type that formed it, and every read checks that version before interpreting the bytes. On a mismatch, the server raises an error instead of reading wrong.

The scheme's details, per the design document:

  • The version is a WAL LSN. The WAL insertion point only moves forward, rollbacks included. That solves ADD COLUMN; ROLLBACK; ADD COLUMN: the new column gets a different version from the rolled-back one.
  • The version is per attribute, not per type. A single per-type version would block reading values formed before an ADD COLUMN, which must keep working.
  • When a column's type changes, its version and every later one bump. The change can shift the position of the fields that follow.
  • Dropping a column changes no version. The dropped column's size and alignment are kept, so old values stay readable.
  • A value is stamped with the version of the last attribute it contains, and reads compare it with that same attribute's version in the descriptor. That allows reading values formed when the type had fewer fields.

To fit in a minor release without changing the catalog's shape, attribute versions are stored in pg_attribute.attoptions under the reserved key pg_attver. In the value, the 8-byte version is split across two tuple-header fields previously unused for composites, and a combined t_infomask bit marks the tuple as a "value" (not a table row). On the main branch, the version moves to its own column, pg_attribute.attversion.

Values created before the upgrade have no version. They are treated as version 0, and any DDL after the upgrade changes the attribute's version. So an old value that became incompatible is blocked too.

2. Stricter rules for ALTER

The second front (Heikki Linnakangas) attacks the problem higher up, stopping the dangerous situations from happening:

  • Altering a column's type is now forbidden by default when other objects depend on the type, except relations and a few cases known to be safe. The logic used to be the reverse: only some kinds of dependency were checked. The commit cites expressions in views as a previously broken case that is now forbidden.
  • Function DEFAULT expressions and new-style SQL function bodies that depend on the type also block the ALTER, per the release notes.
  • Types used by foreign tables can no longer change, because the foreign table's statistics may hold values in the old layout.
  • A race condition was closed: an uncommitted CREATE TABLE or ADD COLUMN using the type now holds its lock to the end, blocking a concurrent ALTER TYPE.

3. Checks across different row types

A third commit (Add checks for cross-rowtype deforming and conversions) covers values read with another relation's descriptor: triggers, EvalPlanQual rechecks of function scans and, mostly, partitioned tables, where rows move between partitions. In those cases the server now checks the descriptors are compatible.

The commit itself warns these checks add nontrivial overhead. The cost is diluted because the paths that reach them are already expensive, like triggers fired by DML on partitioned tables.

The size of the change

The central commit alone adds 2,634 lines and removes 391, across 50 files. Most of it is in tuple access code and the catalog:

Lines added in the fix's central commit, by code arealines
Lines added in the fix's central commit, by code area
Lines added
Tuple access861
Catalog (incl. design doc)655
Headers284
Tests223
Utilities and cache160
Executor135
ALTER commands126
pg_dump119
Other71

Commit 245eb832f8 in the official postgres/postgres mirror

It is an infrastructure change, backpatched down to version 14 (backpatch-through: 14). It isn't a patch you apply and forget: it changes behavior.

What changes for whoever runs the database

This is the part that affects teams most. The list comes from the central commit message and the release notes.

C extensions must be rebuilt

For full protection, extensions written in C must be rebuilt, and some will need source changes. DatumGetHeapTupleHeader() is no longer a macro. Consequences described in the commit:

  • an extension built against the new release can fail with a linker error if loaded on an earlier minor release;
  • a non-rebuilt extension can see HeapTupleHeaderGetTypMod() return part of the version instead of -1;
  • code that forms tuples and then edits certain internal fields can trigger spurious errors. The commit lists known cases the check tolerates.

Downgrading after DDL is risky

Updating to the fixed release, running DDL, going back to the previous release and updating again can cause errors for composite values formed while downgraded. DDL run while downgraded can break the version invariants. In practice: treat this update as one-way and test first.

pg_dump and pg_upgrade

  • Dumps of a fixed server made with an older pg_dump contain ALTER COLUMN ... SET (pg_attver = ...), which servers without the fix reject. Use the pg_dump matching the server.
  • Since pg_upgrade uses the target's pg_dump, upgrading from a minor release with the fix to a later major release without it fails. When planning a major upgrade, make sure the target is fixed too.
  • Tools reading pg_attribute.attoptions will see the new pg_attver key. ALTER COLUMN ... SET (pg_attver = ...) is deliberately ignored so older restores don't break.

Schema migrations that may start failing

Under the new rules, some ALTER COLUMN TYPE and ALTER TYPE ... ALTER ATTRIBUTE statements that used to work will now error: when views have expressions over the type, functions have a DEFAULT or SQL body depending on it, or foreign tables use it. Run pending migrations in an already-updated test environment before production.

The composite_type_mismatch parameter

The fix adds a parameter, composite_type_mismatch, with three values: error (default), warn and disabled. It exists as an escape hatch for extension problems and for data recovery. The documentation is clear: values other than error "may cause crashes, wrong results, or other serious problems", and only superusers or users with the matching SET privilege can change it. It lives in the developer options, which "should never be used on a production database".

Keep composite_type_mismatch at error. Switching to warn or disabled turns off the very protection for this CVE. If an extension breaks after the upgrade, rebuild or update the extension, don't disable the check.

Other care points in the same release

The migration section of the 18.7 and 16.16 notes also flags two points that aren't this CVE but ship in the same upgrade:

  • several bugs that could corrupt indexes were fixed: review the entries mentioning REINDEX and reindex affected indexes;
  • on 18.x, existing incremental backups should not be trusted: take a new full backup after updating and use it as the base for later incrementals.

Upgrade checklist

  1. Inventory. Run SELECT version(); on every instance, including replicas, test environments and databases running in containers.
  2. Extensions. List installed extensions with SELECT extname, extversion FROM pg_extension; and identify the C ones that don't ship with PostgreSQL itself. Confirm with each vendor that a build exists for the new release.
  3. Test migrations. In an already-updated environment, run pending schema migrations, especially those changing column types.
  4. No way back. Plan it as one-way: don't run DDL on an updated server if you might roll back to the previous release.
  5. Update. Swap binaries for your branch's minor release (18.7, 17.12, 16.16, 15.20 or 14.25) and restart. No dump/restore needed.
  6. After. Check SHOW composite_type_mismatch; (it should be error), follow the release's REINDEX guidance and, on 18.x, take a fresh full backup.
  7. Watch. Follow the logs for the first days: new composite-type mismatch errors point to extensions or code that need adjusting.

Where Leavory fits

Step 1 takes the longest in companies with many databases and images. Leavory Image Scan rescans images every day and alerts by e-mail, Microsoft Teams or Slack when a new CVE reaches something already running, like a Postgres image that fell behind. On the platform, vulnerabilities only show up when they hit a package you actually use, with exploited ones first.

Sources

Written by

Leavory Team Leavory team

Engineering and security at Leavory

The people who build Leavory. We write about what we learn running vulnerability management, pipelines and Kubernetes for our customers and for ourselves.

LinkedIn

See Leavory in action.

Tell us which platform you use, and an engineer, not a sales bot, will reach out to schedule a demo.

Which platform do you use?

A real conversation with an engineer.