CVE-2024-7348 Overview
A Time-of-check Time-of-use (TOCTOU) race condition vulnerability has been identified in PostgreSQL's pg_dump utility. This critical flaw allows an object creator to execute arbitrary SQL functions as the user running pg_dump, which is often a superuser with elevated database privileges. The attack involves replacing another relation type with a view or foreign table during the dump operation.
Critical Impact
An attacker with database object creation privileges can exploit this race condition to execute arbitrary SQL functions with superuser privileges, potentially leading to complete database compromise, data exfiltration, or further lateral movement within the infrastructure.
Affected Products
- PostgreSQL versions before 16.4
- PostgreSQL versions before 15.8
- PostgreSQL versions before 14.13
- PostgreSQL versions before 13.16
- PostgreSQL versions before 12.20
Discovery Timeline
- August 8, 2024 - CVE-2024-7348 published to NVD
- November 21, 2024 - Last updated in NVD database
Technical Details for CVE-2024-7348
Vulnerability Analysis
This vulnerability stems from a classic Time-of-check Time-of-use (TOCTOU) race condition in the pg_dump utility. The flaw occurs during the database backup process when pg_dump checks and then subsequently uses database objects. Between these two operations, an attacker with object creation privileges can replace a legitimate relation type (such as a table) with a malicious view or foreign table.
The attack requires the attacker to retain an open transaction, which makes winning the race condition trivial. When pg_dump processes the substituted object, it executes any associated SQL functions in the context of the user running the dump operation—typically a superuser account. This privilege escalation can lead to arbitrary code execution within the database context, unauthorized data access, or complete database compromise.
Root Cause
The root cause is a TOCTOU race condition in pg_dump's object handling logic. The utility performs a check on database objects at one point in time but then operates on them at a later point without re-verifying their state. This temporal gap between checking and using creates a window of opportunity for an attacker to substitute a malicious object. The design flaw fails to implement proper locking mechanisms or atomic operations that would prevent object modification during the critical dump operation window.
Attack Vector
The attack is network-accessible and requires the attacker to have low-level privileges (specifically, the ability to create database objects). While the attack complexity is high due to the race condition timing requirement, the attacker can trivially win the race by maintaining an open database transaction.
The attack sequence involves:
- An attacker with object creation privileges monitors for pg_dump operations to begin
- The attacker maintains an open transaction to extend the race window
- When pg_dump starts processing objects, the attacker replaces a legitimate relation with a malicious view or foreign table containing arbitrary SQL functions
- pg_dump executes the malicious SQL functions with elevated privileges (typically superuser)
The vulnerability mechanism involves object substitution during the pg_dump process. When pg_dump enumerates database objects, an attacker can replace a relation with a view containing malicious function calls. Since the attacker can hold an open transaction, the timing window becomes exploitable. For detailed technical information, refer to the PostgreSQL Security Advisory CVE-2024-7348.
Detection Methods for CVE-2024-7348
Indicators of Compromise
- Unexpected creation or modification of views or foreign tables coinciding with pg_dump operations
- Unusual superuser activity or privilege escalation events in PostgreSQL logs
- Database objects being replaced or altered during backup windows
- Open transactions held by untrusted users during backup operations
Detection Strategies
- Monitor PostgreSQL logs for suspicious DDL operations (CREATE VIEW, CREATE FOREIGN TABLE) occurring during pg_dump execution windows
- Implement auditing on database object creation and modification events, particularly for relation replacements
- Track long-running or open transactions from non-administrative users that coincide with backup schedules
- Use PostgreSQL's log_statement = 'ddl' configuration to capture all DDL operations for forensic analysis
Monitoring Recommendations
- Configure alerts for backup job anomalies or failures that may indicate exploitation attempts
- Monitor process execution to detect concurrent pg_dump operations and suspicious database sessions
- Implement real-time monitoring of database privilege usage patterns, especially superuser function execution
- Review backup logs for unexpected object types or content that differs from baseline expectations
How to Mitigate CVE-2024-7348
Immediate Actions Required
- Upgrade PostgreSQL to patched versions: 16.4, 15.8, 14.13, 13.16, or 12.20 immediately
- Restrict database object creation privileges to trusted users only
- Review and audit existing database objects for unauthorized modifications before running pg_dump
- Consider running backups during maintenance windows with restricted user access
Patch Information
PostgreSQL has released security patches addressing this TOCTOU vulnerability. Organizations should upgrade to the following minimum versions:
| Current Version Branch | Upgrade To |
|---|---|
| PostgreSQL 16.x | 16.4 or later |
| PostgreSQL 15.x | 15.8 or later |
| PostgreSQL 14.x | 14.13 or later |
| PostgreSQL 13.x | 13.16 or later |
| PostgreSQL 12.x | 12.20 or later |
For complete patch details and download links, refer to the PostgreSQL Security Advisory CVE-2024-7348.
Workarounds
- Restrict CREATE privileges on schemas to prevent unauthorized object creation during dump operations
- Schedule pg_dump operations during maintenance windows when user activity is minimal
- Run pg_dump with a dedicated user that has read-only access rather than superuser privileges where feasible
- Implement network isolation for backup operations to limit attacker access during vulnerable windows
# Restrict object creation privileges - revoke from public
psql -c "REVOKE CREATE ON SCHEMA public FROM PUBLIC;"
# Configure enhanced logging for DDL operations
# Add to postgresql.conf:
# log_statement = 'ddl'
# log_min_duration_statement = 0
# Run pg_dump with specific user instead of superuser where possible
pg_dump -U backup_readonly_user -d mydatabase > backup.sql
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


