Skip to main content
Vulnerability Database/CVE-2026-85748

CVE-2026-85748: MariaDB Use-After-Free Vulnerability

CVE-2026-85748 is a use-after-free vulnerability in MariaDB server that affects SYS_REFCURSOR handling, potentially enabling remote code execution. This article covers technical details, affected versions, and mitigation.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-85748 Overview

CVE-2026-85748 is a use-after-free vulnerability [CWE-416] in MariaDB server affecting SYS_REFCURSOR handling. The flaw exists in cursor-array reallocation logic, which can leave stale references in routine contexts. A low-privileged authenticated attacker can open a large number of SYS_REFCURSOR instances and then fetch one to trigger memory corruption. When chained with another vulnerability, this condition can enable remote code execution against the database server. The issue affects MariaDB versions from 12.3.1 up to (but not including) 12.3.3, and version 13.0.1. Fixed releases are 12.3.3 and 13.0.2.

Critical Impact

Authenticated attackers can trigger a use-after-free in the MariaDB server process, potentially leading to remote code execution and full compromise of the database host.

Affected Products

  • MariaDB server versions 12.3.1 through 12.3.2
  • MariaDB server version 13.0.1
  • Fixed in MariaDB 12.3.3 and 13.0.2

Discovery Timeline

  • 2026-10-16 - CVE-2026-85748 published to NVD
  • 2026-10-20 - Last updated in NVD database

Technical Details for CVE-2026-85748

Vulnerability Analysis

The vulnerability resides in MariaDB's stored routine cursor subsystem, specifically in the sp_cursor_array class used to manage SYS_REFCURSOR objects within a function or procedure context. When a routine opens many cursors, the underlying dynamic array holding sp_cursor_array_element values is reallocated to accommodate growth. The reallocation moves the backing storage, but existing references to prior element locations are not invalidated. Subsequent FETCH operations against a cursor still pointing to freed memory dereference a stale pointer, corrupting the server process state. The bug is tracked upstream as MDEV-40396 and MDEV-40639.

Root Cause

The root cause is a lifetime mismatch between cursor references held in routine contexts and the storage managed by Dynamic_array<sp_cursor_array_element>. Because the array stored elements by value, any realloc-style growth invalidated outstanding pointers to array slots. The upstream fix changes the container to Dynamic_array<sp_cursor_array_element*>, storing stable heap-allocated pointers that survive array growth.

Attack Vector

An authenticated user with permission to create or execute stored routines can craft a function that allocates a large number of SYS_REFCURSOR values, forcing the cursor array to reallocate. Fetching from a cursor whose backing element has been freed triggers the use-after-free. The attack requires only low privileges and no user interaction, and operates over the network against the database service. When combined with a secondary memory corruption primitive, the condition is suitable for achieving remote code execution in the context of the mysqld process.

c
// Patch excerpt: sql/sp_cursor.h - MDEV-40639
-class sp_cursor_array: public Dynamic_array<sp_cursor_array_element>
+class sp_cursor_array: public Dynamic_array<sp_cursor_array_element*>
 {
 protected:
   Type_ref_null find_unused()
   {
     for (size_t i= 0 ; i < size(); i++)
     {
-      if (!at(i).is_open() && !at(i).ref_count())
+      if (!at(i)->is_open() && !at(i)->ref_count())
         return Type_ref_null((ulonglong) i);
     }
     return Type_ref_null();

Source: MariaDB commit 91156c3

c
// Patch excerpt: sql/sp_cursor.cc - safer allocation and error path
 Type_ref_null sp_cursor_array::append(THD *thd)
 {
-  if (Dynamic_array::append(sp_cursor_array_element()))
+  sp_cursor_array_element *elem= new sp_cursor_array_element();
+  if (!elem || Dynamic_array::append(elem))
   {
+    if (!elem)
+      my_error(ER_OUTOFMEMORY, MYF(0), (int) sizeof(sp_cursor_array_element));
     DBUG_ASSERT(thd->is_error());
     return Type_ref_null();
   }

Source: MariaDB commit 91156c3

Detection Methods for CVE-2026-85748

Indicators of Compromise

  • Unexpected mysqld process crashes or restarts, especially segmentation faults referenced in the MariaDB error log while executing stored routines.
  • Stored functions or procedures that declare and open an unusually large number of SYS_REFCURSOR variables.
  • Database authentication by low-privileged accounts followed by execution of newly created routines that manipulate many cursors.

Detection Strategies

  • Audit stored routine definitions for abnormal patterns of SYS_REFCURSOR allocation and FETCH operations in short loops.
  • Enable the MariaDB general query log or audit plugin to capture CREATE FUNCTION, CREATE PROCEDURE, and CALL statements from non-administrative accounts.
  • Correlate mysqld crash telemetry with recent routine executions to identify triggering sessions.

Monitoring Recommendations

  • Alert on repeated mysqld service restarts and core dump creation on database hosts.
  • Monitor privilege grants that allow routine creation (CREATE ROUTINE) and track their usage.
  • Forward database audit events and host process telemetry to a centralized analytics platform for correlation across sessions and hosts.

How to Mitigate CVE-2026-85748

Immediate Actions Required

  • Upgrade MariaDB server to version 12.3.3 or 13.0.2 as a priority on all affected hosts.
  • Inventory database accounts with CREATE ROUTINE or EXECUTE privileges and remove entitlements that are not strictly required.
  • Review recently created or modified stored routines for anomalous SYS_REFCURSOR usage.

Patch Information

The vulnerability is fixed in MariaDB 12.3.3 and 13.0.2. The fix is documented in MariaDB Security Advisory GHSA-mv8g-9f7q-hprm and implemented in commits 91156c3 and 9b075b2, tracked as MDEV-40396 and MDEV-40639.

Workarounds

  • Restrict CREATE ROUTINE and ALTER ROUTINE privileges to trusted administrators until patches are deployed.
  • Block direct network access to the MariaDB port from untrusted networks and require authenticated bastion access.
  • Review and remove stored routines that declare or manipulate SYS_REFCURSOR values if their functionality is not required.
bash
# Example: revoke routine creation from a low-privileged user as a temporary control
mysql -u root -p -e "REVOKE CREATE ROUTINE, ALTER ROUTINE ON *.* FROM 'appuser'@'%'; FLUSH PRIVILEGES;"

# Verify installed MariaDB version after patching
mysql -u root -p -e "SELECT VERSION();"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.