CVE-2021-33204
📋 TL;DR
This vulnerability in pg_partman (PostgreSQL Partition Manager) allows arbitrary code execution via SECURITY DEFINER functions that don't set an explicit search_path. Attackers can exploit this to execute malicious SQL commands with elevated privileges. Any PostgreSQL installation using pg_partman extension versions before 4.5.1 is affected.
💻 Affected Systems
- pg_partman (PostgreSQL Partition Manager)
📦 What is this software?
⚠️ Risk & Real-World Impact
Worst Case
Full database compromise leading to data theft, data destruction, or complete system takeover via privilege escalation to database superuser.
Likely Case
Unauthorized data access, privilege escalation within the database, and potential lateral movement to other systems.
If Mitigated
Limited impact if proper network segmentation and least privilege database access controls are implemented.
🎯 Exploit Status
Exploitation requires database access (authenticated user). The vulnerability is in SECURITY DEFINER functions which execute with elevated privileges when called by lower-privileged users.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: 4.5.1
Vendor Advisory: https://github.com/pgpartman/pg_partman/commit/0b6565ad378c358f8a6cd1d48ddc482eb7f854d3
Restart Required: No
Instructions:
1. Update pg_partman to version 4.5.1 or later. 2. Run: ALTER EXTENSION pg_partman UPDATE TO '4.5.1'; 3. Verify the update completed successfully.
🔧 Temporary Workarounds
Revoke execute permissions on vulnerable functions
allTemporarily remove execute permissions from non-superusers on pg_partman's SECURITY DEFINER functions
REVOKE EXECUTE ON FUNCTION function_name FROM public;
REVOKE EXECUTE ON FUNCTION function_name FROM [specific_users];
Set explicit search_path
allModify vulnerable functions to include SET search_path = pg_catalog
ALTER FUNCTION function_name SET search_path = pg_catalog;
🧯 If You Can't Patch
- Implement strict database user access controls and principle of least privilege
- Network segment PostgreSQL databases and restrict access to trusted sources only
🔍 How to Verify
Check if Vulnerable:
Check pg_partman version: SELECT * FROM pg_available_extensions WHERE name = 'pg_partman'; If version < 4.5.1, system is vulnerable.
Check Version:
SELECT * FROM pg_available_extensions WHERE name = 'pg_partman';
Verify Fix Applied:
Verify pg_partman version is 4.5.1 or later: SELECT * FROM pg_available_extensions WHERE name = 'pg_partman';
📡 Detection & Monitoring
Log Indicators:
- Unusual database function calls to pg_partman functions
- Privilege escalation attempts in PostgreSQL logs
- Unexpected SECURITY DEFINER function executions
Network Indicators:
- Unusual database connection patterns to PostgreSQL instances with pg_partman
SIEM Query:
source="postgresql" AND ("pg_partman" OR "SECURITY DEFINER") AND (privilege_escalation OR unauthorized_access)
🔗 References
- https://github.com/pgpartman/pg_partman/commit/0b6565ad378c358f8a6cd1d48ddc482eb7f854d3
- https://github.com/pgpartman/pg_partman/compare/v4.5.0...v4.5.1
- https://security.netapp.com/advisory/ntap-20210625-0006/
- https://github.com/pgpartman/pg_partman/commit/0b6565ad378c358f8a6cd1d48ddc482eb7f854d3
- https://github.com/pgpartman/pg_partman/compare/v4.5.0...v4.5.1
- https://security.netapp.com/advisory/ntap-20210625-0006/