Automated Threat Modeling

Overview of CVE-2026-120150: PostgreSQL Expanded Record Domain Check Use After Free Enabling Code Execution

A brief summary of CVE-2026-120150, a use-after-free in PostgreSQL expanded record domain checks that lets an object creator execute code as the database OS user. The post covers the root cause, the one-line upstream fix, and the fixed minor releases.

CVE Analysis

6 min read

Gaurav Sarraf
Gaurav Sarraf

2026-11-12

Overview of CVE-2026-120150: PostgreSQL Expanded Record Domain Check Use After Free Enabling Code Execution

Introduction

A memory lifetime bug in the way PostgreSQL validates domains over composite types lets a database role that can create objects run arbitrary code as the operating system account hosting the database server. For deployments that hand object creation rights to application roles, tenants, or analysts, that turns a low-privilege SQL login into a foothold on the database host itself.

The issue, tracked as CVE-2026-120150 and classified as CWE 416 (Use After Free), carries a CVSS 3.1 score of 8.8 (High) with vector AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H. The attacker must be authenticated and needs low privileges, and the advisory specifically describes an object creator as the trigger. PostgreSQL shipped fixes on November 12, 2026 in 18.7, 17.12, 16.16, 15.20 and 14.25. Tom Lane wrote the fix, and the release notes credit Claude and Ada Logics with the report.

Technical information

Background: expanded records and domain checks

An expanded record is PostgreSQL's in-memory form of a composite (row) value. When a value is assigned to a domain defined over a composite type, the server has to evaluate that domain's constraints. Rather than building a full new record for each check, it uses a lightweight dummy expanded record that borrows the parent record's data. That dummy is constructed by build_dummy_expanded_header() in src/backend/utils/adt/expandedrecord.c, which copies fields such as fvalue, fstartptr and fendptr from the main header.

Root cause

The bug is a memory context ownership problem, and the fixing commit message lays it out step by step:

  1. The dummy header's eoh_context is set to the parent's er_short_term_cxt.
  2. If an operation on the dummy record needs its own short-term context, that context is created as a child of the parent's short-term context.
  3. When the callers of build_dummy_expanded_header() finish, they reset the parent's er_short_term_cxt. Resetting a memory context also deletes its children, so the dummy's short-term context is freed.
  4. The dummy header itself is reused, and its er_short_term_cxt field still holds the old address. On the next domain check, the code uses that dangling pointer, which in the commit's words "often will now be pointing at some other unrelated context."

So the first check works normally, the cleanup at the end of that check frees the child context, and the second check operates on memory that the allocator may already have handed to something else. The commit notes this "at least risks a crash" and that it was reported to be exploitable for arbitrary code execution.

Attack flow

Based on the advisory and commit message, exploitation follows this general shape:

  1. The attacker authenticates to PostgreSQL over the network with a low-privilege role that can create objects.
  2. The attacker works with a domain over a composite type, so that assignments to it go through the expanded record domain check path and its dummy header.
  3. A first domain check causes the dummy record to create a short-term context as a child of the parent's short-term context. The caller then resets the parent context, which frees that child.
  4. A repeated domain check reuses the dummy header, which still references the freed context through er_short_term_cxt.
  5. Operations through the stale pointer act on whatever now occupies that memory. According to the advisory, this can be turned into arbitrary code execution as the operating system user running the database.

The advisory does not publish the exact SQL statements, the specific object creation privilege needed, or a complete exploitation sequence, and we have not attempted to reconstruct one here.

Impact

Code execution as the database service account generally means full read and write access to every database in the cluster, regardless of SQL-level permissions, plus whatever that OS account can reach on the host. This matches the CVSS ratings of high confidentiality, integrity and availability impact.

Patch information

The fix is commit 2d91c1c78aea39285c85fae29c5737a4106eeaf0, which avoids using a dangling pointer in expanded record domain checks. It was authored by Tom Lane, committed by Noah Misch, and dated November 9, 2026. Its trailers mark it for backpatching through version 14 and tag it with Security: CVE-2026-120150. The 18.7 release notes describe it as a fix for use after free in expanded record domain constraint checking and link to 2d91c1c78. Backport commits on older branches have different hashes.

The change touches one file, src/backend/utils/adt/expandedrecord.c, adding 16 lines and removing none. Only one of those lines is executable. At the end of build_dummy_expanded_header(), right after the fvalue, fstartptr and fendptr fields are copied from the main header, the patch sets the dummy header's er_short_term_cxt field to NULL.

The patch leaves context ownership as it was and makes the dummy header forget the pointer at the start of every use. The added comment explains that a new short-term context is created "if needed" in each cycle of usage, so a NULL value means no context exists yet and one should be made on demand. As a result, the pointer cannot go stale: whenever the parent's reset frees the old child context, the next cycle drops the reference before anything uses it. The change also introduces no leak, because any new child context still lives under the parent's short-term context, which callers reset when they finish.

A second comment notes that the dummy header's er_dummy_header, er_domaininfo and er_mcb fields are never used on the dummy, so they cannot carry a stale pointer that gets dereferenced. Because the change only adds code, it has no effect on disk formats or catalogs. No action is needed after updating beyond running the fixed binaries. Installing a fixed minor release is still the only way to obtain the fix, since the advisory lists no workaround.

Affected systems and versions

All PostgreSQL server versions earlier than the fixed release in each supported branch are affected:

  • PostgreSQL 18: versions before 18.7 (fixed in 18.7)
  • PostgreSQL 17: versions before 17.12 (fixed in 17.12)
  • PostgreSQL 16: versions before 16.16 (fixed in 16.16)
  • PostgreSQL 15: versions before 15.20 (fixed in 15.20)
  • PostgreSQL 14: versions before 14.25 (fixed in 14.25)

All five fixed releases were published on November 12, 2026. Exploitation requires an authenticated role able to create the relevant objects, so environments where untrusted or semi-trusted users hold object creation rights carry the most exposure.

The NVD record does not identify active exploitation, a known public exploit, or threat actors. The CVE profile we reviewed shows KEV status as no and an EPSS score of 0.00000. Those are indicators rather than proof of absence, and the commit itself states the bug was reported as exploitable for code execution.

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