PostgreSQL pg_stat_statements Extension Heap-based Buffer Overflow Remote Code Execution Vulnerability
A heap-based buffer overflow exists in PostgreSQL's pg_stat_statements extension when processing query normalisations, because user-supplied data length is not validated before copying to a heap buffer. An authenticated attacker could exploit this to execute arbitrary code as the service account.
Originally disclosed on Zero Day Initiative
This vulnerability allows remote attackers to execute arbitrary code on affected installations of PostgreSQL. Authentication is required to exploit this vulnerability.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the query normalisation code in pg_stat_statements copies user-controlled data into a heap buffer without first checking that the data fits.
Impact
An authenticated remote attacker could execute arbitrary code in the context of the PostgreSQL service account.
What the attacker needed
Authentication to PostgreSQL; pg_stat_statements extension enabled
The fix
PostgreSQL issued an update to correct the vulnerability.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
PostgreSQL is a database server. The pg_stat_statements extension records statistics about queries. A buffer overflow happens when a program copies more data into a fixed-size memory area than it can hold, which can corrupt nearby memory and let an attacker run their own code. Here, an attacker who can log in and send specially crafted queries could take over the database process.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.