← Thu, Nov 12 digest

Turning a 22-year-old Postgres type-confusion primitive into RCE

read article ↗ hn thread ↗

A researcher discovered a 22-year-old type-confusion vulnerability in PostgreSQL core, triggered by altering a composite type between statement preparation and execution, enabling remote code execution.

read it This detailed technical walkthrough offers a rare, step-by-step breakdown of turning a database type confusion into a memory corruption exploit.

summary

The author details how manipulating a composite type schema between statement preparation and execution causes PostgreSQL to misinterpret data types, leading to a type-confusion bug. By substituting a controlled UUID payload into a bytea context, the engine dereferences a pointer to a fake method table, enabling arbitrary code execution. Furthermore, a similar array type confusion allows leaking memory addresses to bypass ASLR. While it requires database access, the vulnerability highlights deep architectural risks in database memory models.

key points

  1. Altering a composite type attribute from uuid to bytea between a prepared statement parse phase and execution causes PostgreSQL to misinterpret raw bytes as a pointer.
  2. Constructing fake expanded object headers and method tables within the payload lets an attacker hijack control flow and execute native functions like system().
  3. A parallel type confusion using unnest on arrays forces PostgreSQL to treat pointers as bigints, leaking memory addresses to defeat ASLR.

who should read it

Security researchers, database engineers, and backend developers working with PostgreSQL internals.

discussion positive

consensus

Commenters debate whether this constitutes true remote code execution or privilege escalation, noting it requires database authentication and primarily threatens multi-tenant environments.

pushback

Some argue that PostgreSQL's reliance on external type mapping is a performance trade-off rather than a fundamental design flaw.

best comment by logophobia ↗

Correct me if I'm wrong, but those all look like sql exploits. Don't those already require some sort of authenticated remote access. They are security issues, but calling them remote code exploitation make them seem more dangerous than they are.

These seem more like privilege escalation, you have access through a database account and use that to gain full access to the whole server. So an issue for multi-tenant databases mostly.

It initiates a debate on security nomenclature, highlighting that authentication requirements change the risk profile from standard network RCE to database privilege escalation.

Generated by an LLM from the article and thread. Check the sources before relying on it.