<Vulnerability name="CVE-2026-116331">
    <DocumentDistribution xml:lang="en">Copyright © 2012 Red Hat, Inc. All rights reserved.</DocumentDistribution>
    <ThreatSeverity>Important</ThreatSeverity>
    <PublicDate>2026-11-12T14:15:17</PublicDate>
    <Bugzilla id="2572566" url="https://bugzilla.redhat.com/show_bug.cgi?id=2572566" xml:lang="en:us">
postgresql: postgresql: Arbitrary code execution via aggregate optimization type confusion
    </Bugzilla>
    <CVSS3 status="verified">
        <CVSS3BaseScore>8.8</CVSS3BaseScore>
        <CVSS3ScoringVector>CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H</CVSS3ScoringVector>
    </CVSS3>
    <CWE>CWE-843</CWE>
    <Details xml:lang="en:us" source="Mitre">
Type confusion in PostgreSQL min/max aggregate optimization allows an object creator to execute arbitrary code as the operating system user running the database, via a user-defined aggregate whose SORTOP option causes the planner to treat the aggregate's input and result as the same type when they differ.  Versions before PostgreSQL 18.7, 17.12, 16.16, 15.20, and 14.25 are affected.
    </Details>
    <Details xml:lang="en:us" source="Red Hat">
A flaw was found in PostgreSQL. An authenticated user with permission to create database objects can exploit this vulnerability to achieve arbitrary code execution as the operating system user running the database service. The issue occurs during query optimization when a user-defined aggregate function specifies a sort operator (SORTOP) that causes the query planner to treat different data types as identical. This data type confusion allows an attacker to manipulate internal memory and compromise the host system.
    </Details>
    <Statement xml:lang="en:us">
This vulnerability is rated as having an Important severity for Red Hat deployments because, although successful exploitation leads to complete arbitrary code execution under the operating system account running the database service, it requires an authenticated attacker with permissions to define custom database objects rather than being exploitable by unauthenticated remote users. In typical enterprise environments, database access is restricted and standard application roles do not possess schema creation privileges, which limits the attack surface to trusted or privileged database accounts. However, in shared hosting or multi-tenant configurations where non-administrative users can create schemas and custom routines, an attacker could leverage this flaw to fully compromise the database host.
    </Statement>
    <Mitigation xml:lang="en:us">
Revoke object creation permissions from untrusted database accounts and restrict network access to trusted administrative hosts.

1. Revoke schema creation permissions to prevent users from defining custom aggregates:
```sql
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
REVOKE CREATE ON SCHEMA &lt;schema_name&gt; FROM &lt;username&gt;;
```

2. Limit network access to trusted clients using firewalld:
```bash
firewall-cmd --permanent --zone=trusted --add-source=&lt;trusted_ip_or_subnet&gt;
firewall-cmd --permanent --zone=public --remove-service=postgresql
firewall-cmd --reload
```
Alternatively, restrict client access rules in `/var/lib/pgsql/data/pg_hba.conf` and apply the configuration:
```bash
systemctl reload postgresql
```

Caveats: Revoking object creation privileges prevents non-administrative users and applications from creating or modifying custom database objects and schemas. Limiting network access will block queries from unlisted client hosts.

Warning: Modifying firewall rules or reloading the PostgreSQL service (`systemctl reload postgresql`) affects service accessibility. Ensure configuration changes are applied during scheduled maintenance windows to prevent unexpected disruption to active sessions.
    </Mitigation>
    <AffectedRelease cpe="cpe:/a:redhat:hummingbird:1">
        <ProductName>Red Hat Hardened Images</ProductName>
        <ReleaseDate>2026-11-13T00:00:00Z</ReleaseDate>
        <Advisory type="RHSA" url="https://access.redhat.com/errata/RHSA-2026:100114">RHSA-2026:100114</Advisory>
        <Package name="postgresql17-main">postgresql17-main-17.12-0.1.hum1</Package>
    </AffectedRelease>
    <AffectedRelease cpe="cpe:/a:redhat:hummingbird:1">
        <ProductName>Red Hat Hardened Images</ProductName>
        <ReleaseDate>2026-11-13T00:00:00Z</ReleaseDate>
        <Advisory type="RHSA" url="https://access.redhat.com/errata/RHSA-2026:100123">RHSA-2026:100123</Advisory>
        <Package name="postgresql18-main">postgresql18-main-18.7-0.1.hum1</Package>
    </AffectedRelease>
    <AffectedRelease cpe="cpe:/a:redhat:hummingbird:1">
        <ProductName>Red Hat Hardened Images</ProductName>
        <ReleaseDate>2026-11-12T00:00:00Z</ReleaseDate>
        <Advisory type="RHSA" url="https://access.redhat.com/errata/RHSA-2026:99821">RHSA-2026:99821</Advisory>
        <Package name="libpq-main">libpq-main-18.7-0.1.hum1</Package>
    </AffectedRelease>
    <References xml:lang="en:us">
https://www.cve.org/CVERecord?id=CVE-2026-116331
https://nvd.nist.gov/vuln/detail/CVE-2026-116331
https://www.postgresql.org/support/security/CVE-2026-116331/
    </References>
</Vulnerability>