MariaDB 13.0.1-rc RCE: Priv-Esc + Heap UAF + JOP Chain to system()
A low-privilege MariaDB account could escalate to full DBA by granting proxy to root with an empty authentication clause, then read the server's own memory map through SQL file reads to defeat ASLR, and finally trigger a use-after-free in the cursor code to run commands as the database user. The author claims the whole chain works with plain SQL statements against the stock Docker image.
Published on medium.com
Mariadb
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.
Context
MariaDB is a widely deployed open-source relational database, and the target here is the stock, unmodified MariaDB 13.0.1-rc Docker image. The feature at the centre of the chain is the server-side cursor machinery: SYS_REFCURSOR cursors are backed by a Dynamic_array of sp_cursor objects, and stored routines can open cursors from inside a cursor's open() method. That reentrancy, combined with the authentication-clause handling of GRANT PROXY and the file-read primitive of LOAD DATA INFILE, is enough to take a low-privilege SQL account to command execution as uid 999 (mysql).
No host access, no docker commands and no direct /proc/<pid>/mem writes are involved: every step is a plain SQL statement. The research was carried out with RAPTOR and raptor-loop-hunt, described as an autonomous offensive research framework and its iterative hunt plugin.

The chain has five steps:
GRANT PROXYprivilege escalation (F-09): any account becomes full DBA.- ASLR defeat via a
/proc/self/mapsleak. - A
SYS_REFCURSORuse-after-free (F-05), unfixed upstream at the time of writing. - Heap spray plus a Jump-Oriented Programming (JOP) chain.
- A pure-SQL trick for resolving a self-referential address, using glibc's mmap slot reuse.
Setup
The only precondition for the full chain is a MariaDB account with USAGE-only privileges and TCP reachability to port 3306. No host shell, no docker commands, no /proc/<pid>/mem access and no root password are needed. The target is the stock 13.0.1-rc Docker image; the privilege-escalation bug was verified from 13.0.1 through 10.6.27.
The repository also keeps a legacy host-assisted PoC, exploit.py, which writes the JOP chain via /proc/<pid>/mem from the Docker host. It is explicitly noted as superseded by the pure-SQL variant.
Finding it
Three separate observations combine into the chain. The first is in the authentication-clause validation path: an empty auth clause is treated as "nothing to validate" by one routine but still applied by another. The second is that the stock image leaves secure_file_priv unset (NULL), so LOAD DATA INFILE can read arbitrary files as the server process. The third is a reentrancy pattern that only exists at the SQL layer: SQL executed from inside a cursor callback grows the very cursor array the callback is iterating over, leaving a cached interior pointer dangling.
Exploitation
Step 1: F-09, privilege escalation by hijacking root via GRANT PROXY
GRANT PROXY ON CURRENT_USER() TO 'root'@'%' IDENTIFIED VIA '' ;
One statement, and any authenticated user becomes a full DBA. The root cause sits in the authentication-clause validation path:
- When the authentication clause is empty, as in
IDENTIFIED VIA '',LEX_USER::has_auth()returnsfalse. - A
falsefromhas_auth()skips the privilege-check routinecheck_alter_user(). - Downstream,
replace_user_table()still applies that empty auth clause, overwriting root's credentials with an empty password.
The gap is between "no auth info supplied, so nothing to validate" and "no auth info supplied, so apply it anyway, even if empty". No special privileges are required, and the bug reproduces on every released MariaDB version. The fix (dbd60d0ad8d, MDEV-40470) exists on dev branches but has not been backported to any release, verified from 13.0.1 through 10.6.27.
Step 2: ASLR defeat by reading /proc/self/maps through SQL
LOAD DATA INFILE '/proc/self/maps' INTO TABLE ...
On the stock image secure_file_priv is unset (NULL). Combined with the FILE privilege, LOAD DATA INFILE can read arbitrary files as the server process, including /proc/self/maps, which hands back the mariadbd process's own memory layout as SQL output. This directly leaks the PIE base and libc base. No separate info-leak bug is required: it is purely the combination of an unset configuration default and a built-in SQL file-read primitive. The addresses change on every run, but since they are read live from the running process each time, that is a non-issue for the exploit.
Step 3: F-05, the SYS_REFCURSOR use-after-free
The vulnerable function is sp_cursor_array::get_cursor_by_ref(). The dispatch that gets hijacked looks like this:
Materialized_cursor::open() -> result->prepare()
-> mov rax, [result] ; rax = attacker's vtable pointer (V)
-> call [rax + 0x20] ; calls the D2 gadget (prepare()'s vtable slot)
get_cursor_by_ref() returns an interior pointer into a Dynamic_array backing the cursor array. The array is managed via my_realloc, and that is where the bug lives:
- Attacker-controlled SQL running inside a cursor's
open()method opens additional cursors. - The cursor array has to grow,
my_reallocallocates new storage, and the old backing storage is freed. - The caller's already-cached pointer into the old storage is never updated, so it is now dangling.
The freed chunk is exactly 16 cursors x 112 bytes = 1792 bytes. A heap spray of 128 user-variable copies, each sized at an exact-fit 1784 bytes, reclaims that chunk. The spray payload plants an attacker-controlled vtable pointer at offset 0x20, the location of sp_cursor's result member, and the next virtual dispatch through that member hijacks control flow.
As of 2026-08-03 the bug was still unfixed upstream: zero commits to sql/sp_cursor.{cc,h} between the 13.0.1 tag and HEAD.
Step 4: the JOP chain, system() without ROP or a stack pivot
Two gadgets from the stock mariadbd binary are enough to reach system():
| Gadget | Offset | Instruction | Purpose |
|---|---|---|---|
| D2 | PIE+0x80da77 | call *0x100(%rax) |
Stack alignment fix |
| D1 | PIE+0xe3075b | mov rdi,[rax+0xa8]; call [rax+0xa0] |
Load command pointer, call system() |
The fake vtable V lives inside the 128 MiB buffer built earlier, laid out as:
V+0x20 = D2 (prepare()
V+0xa0 = system() (libc+0x5c560)
V+0xa8 = V+0x140 (pointer to the command string -> loaded into rdi)
V+0x100 = D1 (JOP dispatcher)
V+0x140 = "sh -c '<cmd>'\0"
This is a classic JOP chain: control flow moves purely through chained virtual-function calls and never touches the stack, so stack canaries and return-address protections are simply irrelevant here.
Step 5: resolving a self-referential address using only SQL
There is a chicken-and-egg problem baked into the layout above: V+0xa8 needs to hold the address of the buffer itself (V+0x140), but that address is not known until the buffer is allocated. This is solved with a quirk of glibc's mmap behaviour.
SET @fake = REPEAT(CHAR(0xDE), 134217728);
-- Step 2: re-allocate with the full JOP layout, self-reference included
SET @fake = CONCAT(REPEAT(...), UNHEX('<JOP layout>'), REPEAT(...));
-- glibc munmaps the old chunk and reuses the exact same slot,
-- so the address discovered in step 1 stays valid
In order:
- Allocate a 128 MiB marker buffer. glibc grants a dedicated mmap region, and its address is recovered via a
/proc/self/mapsdiff. - Re-allocate the same variable with the complete layout. glibc reuses the same mmap slot, so the self-reference baked in during step 1 remains valid.
- Each step re-reads
/proc/self/mapsto verify; if the address ever moved, the self-reference is re-baked and the write retried (it converges in one iteration in practice).
The choice of 128 MiB is deliberate: glibc's dynamic mmap threshold can grow past 4 MiB after large frees, and 128 MiB reliably lands a dedicated mmap region regardless (128 MiB and 256 MiB were both verified). One catch: a buffer larger than max_allowed_packet simply fails, so SET GLOBAL max_allowed_packet has to be raised first, with a fresh connection afterwards. The +0x30 data offset within the mmap region is also glibc/image-specific and is exposed as a DATA_OFF constant in the code for that reason.
Full attack flow
1. GRANT PROXY ... -> root account hijacked (F-09)
2. LOAD DATA INFILE '/proc/self/maps' -> PIE/libc base recovered (ASLR defeat)
3. SET @fake = REPEAT(...) 128MiB -> mmap slot secured, address found via diff
4. SET @fake = CONCAT(... UNHEX(...)) -> self-referential JOP layout written
5. CALL uaf5 -> SYS_REFCURSOR UAF triggered (F-05)
-> heap spray reclaims the freed chunk
-> result->prepare() virtual call
-> D2 -> D1 -> system("sh -c '<cmd>'")
6. mariadbd is PID 1 -> container exits right after system() returns
-> restart, read the marker file as proof
Root cause
F-09 is a pure logic bug in the auth-clause validation path, not a memory-safety issue, yet by itself it is a complete DBA takeover. The validation routine is skipped precisely when the clause is empty, while the routine that applies the clause does not distinguish empty from absent.
F-05 is a lifetime bug: get_cursor_by_ref() hands out an interior pointer into a Dynamic_array that my_realloc can move and free underneath the caller. The trigger is a reentrancy pattern that only exists at the SQL layer, because SQL executed from inside a cursor callback grows the very cursor array the callback is iterating over.
The ASLR defeat needs no separate info-leak vulnerability: an unset secure_file_priv plus LOAD DATA INFILE is enough to pull /proc/self/maps straight out through SQL. The JOP chain sidesteps stack-based mitigations entirely because it never returns through the stack.
Impact
An attacker holding a MariaDB account with USAGE-only privileges and TCP reachability to port 3306 can escalate to full DBA with a single statement, defeat ASLR, trigger the use-after-free, and reach system() as uid 999 (mysql). Because mariadbd is PID 1 in the container, the container exits right after system() returns; after a restart the marker file can be read as proof. From heap grooming to resolving a self-referential pointer, SQL statements themselves are the exploitation primitive, with no /proc/<pid>/mem writes and no host-side tooling, and a correspondingly much smaller detection surface than the traditional approach.
Fix
The fix for F-09 is commit dbd60d0ad8d (MDEV-40470). It exists on dev branches but has not been backported to any release, verified from 13.0.1 through 10.6.27. F-05 was still unfixed upstream as of 2026-08-03, with zero commits to sql/sp_cursor.{cc,h} between the 13.0.1 tag and HEAD.
Variants to test
- Run the
GRANT PROXYstatement from a USAGE-only account on any released MariaDB version. A positive result is that the account becomes a full DBA and root's credentials are replaced with an empty password. - Check whether
secure_file_privis NULL on a target and whether the account holds FILE. A positive result isLOAD DATA INFILE '/proc/self/maps'returning the server's memory layout as SQL output. - Open additional cursors from inside a cursor's
open()method to grow the cursor array. A positive result is a dangling pointer into the freed 1792-byte chunk, reclaimed by an exact-fit spray. - Allocate a 128 MiB user variable, read
/proc/self/mapsto find its region, then re-allocate the same variable and check whether glibc reuses the same mmap slot. A positive result is the address staying valid across the re-allocation.
What happened, in plain words
A database is a program that stores information in tables and answers questions about it. MariaDB is one such database, and it is open source, meaning anyone can read and change its code. Many websites and companies run it. The version examined here is MariaDB 13.0.1-rc, packaged as a Docker image. A Docker image is a ready-made bundle containing a program and everything it needs to run, so you can start it with one command and get exactly the same setup as everyone else. "Stock" means nobody changed anything in that bundle: it is the version you download and run as-is.

The finding is that a person with a very ordinary database login, one that can do almost nothing, can send a handful of ordinary database commands and end up running their own system commands on the server, as the user the database runs under (uid 999, named mysql). They never need a shell on the machine, never need Docker commands, and never need the root password. Every step is a normal SQL statement, the language you use to talk to a database.
The research was done with tools called RAPTOR and raptor-loop-hunt, described as an autonomous offensive research framework and its iterative hunt plugin.
The chain has five steps:
- A privilege escalation through a database command called
GRANT PROXY(labelled F-09): any account becomes a full database administrator. - Defeating ASLR, a defence that randomises where things sit in memory, by reading a file called
/proc/self/mapsthrough SQL. - A use-after-free bug (labelled F-05) in a feature called
SYS_REFCURSOR, which was still unfixed upstream when the write-up was published. - A heap spray plus a Jump-Oriented Programming (JOP) chain, two techniques for taking control of a program's execution.
- A pure-SQL trick for resolving a self-referential address, using a quirk in how glibc (the standard C library on Linux) reuses memory slots.
Setup
The only precondition for the full chain is a MariaDB account with USAGE-only privileges and TCP reachability to port 3306. Let us unpack that.
- **
USAGE-onlyis the privilege level the report names for the attacker's account: it can log in, and the chain needs nothing more. Think of it as a visitor badge that opens the front door of a building but no rooms. - TCP reachability to port 3306 means the attacker's computer can open a network connection to the port where the database listens. Ports are numbered doors on a machine; 3306 is the default door for MariaDB and MySQL. If you can reach that door from your computer, you can try to log in.
No host shell (a command prompt on the underlying machine), no Docker commands, no /proc/<pid>/mem access and no root password are needed. /proc/<pid>/mem is a special file on Linux that lets a privileged process read and write another process's memory; the report's legacy host-assisted PoC used it, and this chain deliberately does not.
The target is the stock 13.0.1-rc Docker image. The privilege-escalation bug was verified from 13.0.1 through 10.6.27, so it is not limited to the newest release.
The repository also keeps a legacy host-assisted PoC, exploit.py, which writes the JOP chain via /proc/<pid>/mem from the Docker host. A PoC, or proof of concept, is a small program that demonstrates an attack works. This older one needed help from the machine hosting the container; it is explicitly noted as superseded by the pure-SQL variant, meaning the newer approach does the same job without that help.
Finding it
Three separate observations combine into the chain.
The first is in the authentication-clause validation path. When you create or change a database account, you can attach an "authentication clause" saying how that account proves who it is, for example with a password. One part of MariaDB treats an empty clause as "nothing to validate" and skips its safety checks, while another part still applies the clause. The two disagree, and that disagreement is the bug.
The second is that the stock image leaves secure_file_priv unset (NULL). secure_file_priv is a MariaDB setting that restricts which folders the database may read files from or write files to. When it is unset, there is no restriction, so a SQL command that reads files can read any file the database process can read.
The third is a reentrancy pattern that only exists at the SQL layer. Reentrancy means a piece of code is entered again while it is still running, like a shop assistant who, halfway through serving you, starts serving someone else and forgets where your order was. Here, SQL executed from inside a cursor callback grows the very cursor array the callback is iterating over, leaving a cached interior pointer dangling. A cursor is a pointer that lets a program walk through the rows of a query result one at a time; an array is a numbered list of items held in memory; a pointer is a memory address; and "dangling" means the pointer still points at a place that has been freed and may now hold something else.
Exploitation
Step 1: F-09, privilege escalation by hijacking root via GRANT PROXY
GRANT PROXY ON CURRENT_USER() TO 'root'@'%' IDENTIFIED VIA '' ;
Line by line:
GRANT PROXY ON CURRENT_USER():GRANTis the SQL command that gives a privilege to an account, andPROXYis the privilege named in the statement.CURRENT_USER()means "the account I am logged in as right now". So this part says: allow proxying on my own account.TO 'root'@'%': the account receiving the privilege.rootis the name, and%is a wildcard meaning "from any host", so this is the root account connecting from anywhere.IDENTIFIED VIA '': the authentication clause, here deliberately empty. It is the empty string between the quotes that triggers the bug.- The trailing
;ends the statement.
One statement, and any authenticated user becomes a full DBA. DBA stands for database administrator, the account with every power over the database. The root cause sits in the authentication-clause validation path:
- When the authentication clause is empty, as in
IDENTIFIED VIA '',LEX_USER::has_auth()returnsfalse.LEX_USERis the internal structure describing an account, andhas_auth()is a small function that answers "does this account have authentication information?". For an empty clause it answers no. - A
falsefromhas_auth()skips the privilege-check routinecheck_alter_user(). That routine is the guard that asks "is the person issuing this command allowed to change this account?". Because the answer to the previous question was no, the guard is never consulted. - Downstream,
replace_user_table()still applies that empty auth clause, overwriting root's credentials with an empty password. This is the function that actually writes the account's settings into the internal table of users.
The gap is between "no auth info supplied, so nothing to validate" and "no auth info supplied, so apply it anyway, even if empty". No special privileges are required, and the bug reproduces on every released MariaDB version. The fix (dbd60d0ad8d, MDEV-40470) exists on dev branches but has not been backported to any release, verified from 13.0.1 through 10.6.27. A commit is a saved change to the source code, identified by a short hash like dbd60d0ad8d; MDEV-40470 is the tracking ticket for the issue; dev branches are the in-progress versions; and backporting means copying a fix from the in-progress version into the released versions. That has not happened, so the released versions remain vulnerable.
Step 2: ASLR defeat by reading /proc/self/maps through SQL
LOAD DATA INFILE '/proc/self/maps' INTO TABLE ...
Line by line:
LOAD DATA INFILEis a MariaDB command that reads a file from the server's disk and loads its contents into a table.'/proc/self/maps'is the file being read. On Linux,/procis a virtual folder that exposes information about running processes.selfmeans "the process doing the reading", so this file describes the memory of the database server itself.mapslists every region of memory the process has, with its start and end addresses.INTO TABLE ...is where the loaded rows go; the report shows the statement with the table name elided.
On the stock image secure_file_priv is unset (NULL). Combined with the FILE privilege, LOAD DATA INFILE can read arbitrary files as the server process, including /proc/self/maps, which hands back the mariadbd process's own memory layout as SQL output. mariadbd is the name of the database server program. The FILE privilege is the permission that allows this command at all.
Why does the memory layout matter? Because of ASLR, Address Space Layout Randomisation. When a program starts, the operating system places its code and libraries at random addresses, so an attacker who wants to jump to a particular function cannot simply hard-code an address. To defeat ASLR you need to learn where things actually landed, and /proc/self/maps tells you exactly that. This directly leaks the PIE base and libc base. PIE stands for Position Independent Executable, the main program's code; libc is the standard C library, which contains functions like system(). The "base" is the starting address of each in memory.
No separate info-leak bug is required: it is purely the combination of an unset configuration default and a built-in SQL file-read primitive. A primitive, in security jargon, is a small capability you can build on. The addresses change on every run, but since they are read live from the running process each time, that is a non-issue for the exploit.
Step 3: F-05, the SYS_REFCURSOR use-after-free
A use-after-free is a memory bug where a program frees a block of memory and then keeps using it. Imagine handing back a locker key at a gym, then walking back to the locker and putting your bag in it; someone else may already have been given that locker. If an attacker can control what is placed in the freed space, the program will read the attacker's data as if it were its own.
The vulnerable function is sp_cursor_array::get_cursor_by_ref(). The dispatch that gets hijacked looks like this:
Materialized_cursor::open() -> result->prepare()
-> mov rax, [result] ; rax = attacker's vtable pointer (V)
-> call [rax + 0x20] ; calls the D2 gadget (prepare()'s vtable slot)
Line by line:
Materialized_cursor::open() -> result->prepare(): when a cursor is opened, the server callsprepare()on an object stored in a member calledresult. The::notation means "theopenfunction belonging toMaterialized_cursor".mov rax, [result]: assembly language, the lowest-level instructions a processor understands.movcopies a value, and the square brackets mean "the contents at this address". So this loads into the registerraxwhatever is stored atresult. A register is a tiny, very fast storage slot inside the processor. In a normal program this value is a pointer to a table of function addresses, called a vtable; here it is the attacker's vtable pointer, labelled V.call [rax + 0x20]: call the function whose address is found 0x20 bytes into that table.0x20is hexadecimal for 32. This is the slot used forprepare(), and because the attacker controls the table, it calls the D2 gadget instead.
get_cursor_by_ref() returns an interior pointer into a Dynamic_array backing the cursor array. Dynamic_array is MariaDB's growable list: when it runs out of room it allocates a bigger block, copies the items over and frees the old block. An interior pointer is a pointer to somewhere inside that block rather than to its start. The array is managed via my_realloc, the function that performs that grow-and-move, and that is where the bug lives:
- Attacker-controlled SQL running inside a cursor's
open()method opens additional cursors. In other words, while the database is busy opening one cursor, the attacker's SQL asks it to open more. - The cursor array has to grow,
my_reallocallocates new storage, and the old backing storage is freed. - The caller's already-cached pointer into the old storage is never updated, so it is now dangling. The caller saved the address earlier and never learns it has moved.
The freed chunk is exactly 16 cursors x 112 bytes = 1792 bytes. A chunk is one block of memory handed out by the allocator. A heap spray of 128 user-variable copies, each sized at an exact-fit 1784 bytes, reclaims that chunk. A heap spray means filling memory with many copies of your data so that one of them lands in the freed space; user variables are named storage slots in a SQL session, written like @name. The spray payload plants an attacker-controlled vtable pointer at offset 0x20, the location of sp_cursor's result member, and the next virtual dispatch through that member hijacks control flow. An offset is a distance from the start of a block; a virtual dispatch is the lookup of which function to call through a vtable, the same mechanism shown in the assembly above.
As of 2026-08-03 the bug was still unfixed upstream: zero commits to sql/sp_cursor.{cc,h} between the 13.0.1 tag and HEAD. Those are the source files holding the cursor code; a tag is a labelled point in the code history, and HEAD is the latest state of the main development line. No changes there means no fix.
Step 4: the JOP chain, system() without ROP or a stack pivot
Normally, to make a program run your command, you redirect its execution to code you supplied. Two classic techniques are ROP (Return-Oriented Programming), which chains together small pieces of existing code by manipulating return addresses on the stack, and a stack pivot, which moves the stack pointer to memory you control. The stack is the region of memory where a program keeps track of which function called which; return addresses are the places it goes back to when a function finishes. Both techniques touch the stack, and both are watched for by defences called stack canaries (secret values placed on the stack to detect tampering) and return-address protections.
This chain avoids the stack entirely. Two gadgets from the stock mariadbd binary are enough to reach system(). A gadget is a short sequence of existing instructions that an attacker can use as a building block. system() is the standard C library function that runs a shell command.
| Gadget | Offset | Instruction | Purpose |
|---|---|---|---|
| D2 | PIE+0x80da77 | call *0x100(%rax) |
Stack alignment fix |
| D1 | PIE+0xe3075b | mov rdi,[rax+0xa8]; call [rax+0xa0] |
Load command pointer, call system() |
Reading the table: the offset is where the gadget sits relative to the PIE base, so once step 2 has leaked that base, the exact address is known. call *0x100(%rax) is the instruction the report lists for gadget D2, used as a stack alignment fix. mov rdi,[rax+0xa8] loads the command pointer into rdi, and call [rax+0xa0] calls the function stored at rax+0xa0, which the layout sets to system(). The first gadget is used to fix stack alignment, a technical requirement of some processors that the stack be aligned to a particular boundary before certain calls.
The fake vtable V lives inside the 128 MiB buffer built earlier, laid out as:
V+0x20 = D2 (prepare()
V+0xa0 = system() (libc+0x5c560)
V+0xa8 = V+0x140 (pointer to the command string -> loaded into rdi)
V+0x100 = D1 (JOP dispatcher)
V+0x140 = "sh -c '<cmd>'\0"
Line by line:
V+0x20 = D2: at offset 0x20 in the fake table sits the address of gadget D2. This is the slot the hijackedprepare()call reaches.V+0xa0 = system(): at offset 0xa0 sits the address ofsystem()in libc, given aslibc+0x5c560.V+0xa8 = V+0x140: at offset 0xa8 sits a pointer to the command string, which lives at offset 0x140 in the same buffer. This is the self-reference that step 5 has to solve.V+0x100 = D1: at offset 0x100 sits gadget D1, the dispatcher that loads the command pointer and callssystem().V+0x140 = "sh -c '<cmd>'\0": the command string itself.sh -ctells the shell to run the following text as a command, and\0is the null byte that marks the end of a string in C.
This is a classic JOP chain: control flow moves purely through chained virtual-function calls and never touches the stack, so stack canaries and return-address protections are simply irrelevant here. JOP stands for Jump-Oriented Programming, the same idea as ROP but using jumps and calls through registers instead of returns.
Step 5: resolving a self-referential address using only SQL
There is a chicken-and-egg problem baked into the layout above: V+0xa8 needs to hold the address of the buffer itself (V+0x140), but that address is not known until the buffer is allocated. You cannot write down where something is before it exists. This is solved with a quirk of glibc's mmap behaviour. mmap is the system call that asks the operating system for a large block of memory; glibc is the library that implements it for programs.
SET @fake = REPEAT(CHAR(0xDE), 134217728);
Line by line:
SET @fake = ...stores a value in the user variable named@fake.REPEAT(CHAR(0xDE), 134217728)builds a string by repeating one character many times.CHAR(0xDE)is the byte with value 0xDE, a marker byte chosen so the buffer is easy to recognise.134217728is 128 MiB, that is, 128 times 1024 times 1024 bytes.- The
;ends the statement.
-- Step 2: re-allocate with the full JOP layout, self-reference included
SET @fake = CONCAT(REPEAT(...), UNHEX('<JOP layout>'), REPEAT(...));
-- glibc munmaps the old chunk and reuses the exact same slot,
-- so the address discovered in step 1 stays valid
Line by line:
--starts a comment, text the database ignores.SET @fake = ...overwrites the same variable with a new value.CONCAT(...)joins several pieces into one string.REPEAT(...)again produces filler, with the details elided as....UNHEX('<JOP layout>')turns a hexadecimal string into raw bytes; the report shows a placeholder here.- The comments explain the trick:
munmapis the system call that releases an mmap region, and glibc tends to hand the next large request the same slot, so the address found in step 1 remains correct.
In order:
- Allocate a 128 MiB marker buffer. glibc grants a dedicated mmap region, and its address is recovered via a
/proc/self/mapsdiff. A diff means comparing the file before and after, and looking for the new line that appeared. - Re-allocate the same variable with the complete layout. glibc reuses the same mmap slot, so the self-reference baked in during step 1 remains valid.
- Each step re-reads
/proc/self/mapsto verify; if the address ever moved, the self-reference is re-baked and the write retried (it converges in one iteration in practice). Converges means it settles on the right answer quickly.
The choice of 128 MiB is deliberate: glibc's dynamic mmap threshold can grow past 4 MiB after large frees, and 128 MiB reliably lands a dedicated mmap region regardless (128 MiB and 256 MiB were both verified). The threshold is the size above which glibc uses mmap instead of the ordinary heap, and it can change at runtime. One catch: a buffer larger than max_allowed_packet simply fails, so SET GLOBAL max_allowed_packet has to be raised first, with a fresh connection afterwards. max_allowed_packet is the largest single message the server will accept; SET GLOBAL changes a server-wide setting, and the report notes a fresh connection is needed afterwards. The +0x30 data offset within the mmap region is also glibc/image-specific and is exposed as a DATA_OFF constant in the code for that reason. In other words, the data does not begin exactly at the start of the region, and how far in it begins depends on the exact library and image, so it is kept as a named constant that can be adjusted.
Full attack flow
1. GRANT PROXY ... -> root account hijacked (F-09)
2. LOAD DATA INFILE '/proc/self/maps' -> PIE/libc base recovered (ASLR defeat)
3. SET @fake = REPEAT(...) 128MiB -> mmap slot secured, address found via diff
4. SET @fake = CONCAT(... UNHEX(...)) -> self-referential JOP layout written
5. CALL uaf5 -> SYS_REFCURSOR UAF triggered (F-05)
-> heap spray reclaims the freed chunk
-> result->prepare() virtual call
-> D2 -> D1 -> system("sh -c '<cmd>'")
6. mariadbd is PID 1 -> container exits right after system() returns
-> restart, read the marker file as proof
Line by line:
- Step 1 runs the
GRANT PROXYstatement, and the root account is hijacked. - Step 2 reads
/proc/self/maps, recovering the PIE and libc base addresses. - Step 3 allocates the 128 MiB variable, securing an mmap slot and finding its address by comparing the maps file.
- Step 4 rewrites the variable with the full layout, including the self-reference.
- Step 5 calls a stored procedure named
uaf5, which triggers the use-after-free. The spray reclaims the freed chunk, the hijackedprepare()call runs, and control passes D2, then D1, thensystem()with the shell command. - Step 6 notes that
mariadbdis PID 1 in the container. PID 1 is the first process started; the report notes mariadbd is PID 1 in the container, so the container exits right aftersystem()returns. So the container exits right aftersystem()returns; after a restart, the marker file can be read as proof that the command ran.
Root cause
F-09 is a pure logic bug in the auth-clause validation path, not a memory-safety issue, yet by itself it is a complete DBA takeover. The validation routine is skipped precisely when the clause is empty, while the routine that applies the clause does not distinguish empty from absent. A logic bug means the program does exactly what it was written to do, but the rules themselves are wrong; no memory is corrupted.
F-05 is a lifetime bug: get_cursor_by_ref() hands out an interior pointer into a Dynamic_array that my_realloc can move and free underneath the caller. A lifetime bug is about how long a piece of memory is allowed to be used. The trigger is a reentrancy pattern that only exists at the SQL layer, because SQL executed from inside a cursor callback grows the very cursor array the callback is iterating over.
The ASLR defeat needs no separate info-leak vulnerability: an unset secure_file_priv plus LOAD DATA INFILE is enough to pull /proc/self/maps straight out through SQL. The JOP chain sidesteps stack-based mitigations entirely because it never returns through the stack.
Impact
An attacker holding a MariaDB account with USAGE-only privileges and TCP reachability to port 3306 can escalate to full DBA with a single statement, defeat ASLR, trigger the use-after-free, and reach system() as uid 999 (mysql). uid is the numeric identifier of a user on Linux; 999 is the account the database runs as, named mysql. Because mariadbd is PID 1 in the container, the container exits right after system() returns; after a restart the marker file can be read as proof. From heap grooming to resolving a self-referential pointer, SQL statements themselves are the exploitation primitive, with no /proc/<pid>/mem writes and no host-side tooling, and a correspondingly much smaller detection surface than the traditional approach. Heap grooming means arranging memory carefully so the right block is freed and the right one is reused; detection surface means the number of traces an attack leaves for monitoring tools to notice.
Fix
The fix for F-09 is commit dbd60d0ad8d (MDEV-40470). It exists on dev branches but has not been backported to any release, verified from 13.0.1 through 10.6.27. F-05 was still unfixed upstream as of 2026-08-03, with zero commits to sql/sp_cursor.{cc,h} between the 13.0.1 tag and HEAD.
Variants to test
- Run the
GRANT PROXYstatement from a USAGE-only account on any released MariaDB version. A positive result is that the account becomes a full DBA and root's credentials are replaced with an empty password. - Check whether
secure_file_privis NULL on a target and whether the account holds FILE. A positive result isLOAD DATA INFILE '/proc/self/maps'returning the server's memory layout as SQL output. - Open additional cursors from inside a cursor's
open()method to grow the cursor array. A positive result is a dangling pointer into the freed 1792-byte chunk, reclaimed by an exact-fit spray. - Allocate a 128 MiB user variable, read
/proc/self/mapsto find its region, then re-allocate the same variable and check whether glibc reuses the same mmap slot. A positive result is the address staying valid across the re-allocation.
Glossary
- ASLR (Address Space Layout Randomisation): a defence that places a program's code and libraries at random memory addresses each time it starts, so an attacker cannot hard-code addresses.
- Authentication clause: the part of an account definition that says how the account proves who it is, such as a password.
- Backport: copying a fix from the in-progress version of software into already-released versions.
- Chunk: one block of memory handed out by the memory allocator.
- Commit: a saved change to source code, identified by a short hash.
- Container: a packaged, isolated runtime for a program, started from an image.
- Cursor: a pointer that lets a program walk through the rows of a query result one at a time.
- Dangling pointer: a pointer that still refers to memory which has been freed.
- DBA (database administrator): the account with every power over a database.
- Docker image: a ready-made bundle containing a program and everything it needs to run.
- Dynamic_array: MariaDB's growable list that reallocates and frees storage as it grows.
- FILE privilege: the MariaDB permission that allows reading and writing files on the server.
- Gadget: a short sequence of existing machine instructions ending in an indirect call or jump, reused as a building block in an attack.
- glibc: the standard C library on Linux, which implements memory allocation and functions like
system(). - Heap spray: filling memory with many copies of attacker data so one lands in a freed block.
- Heap grooming: arranging memory allocations and frees so a specific block is freed and reused as intended.
- Interior pointer: a pointer to somewhere inside a block of memory rather than to its start.
- JOP (Jump-Oriented Programming): chaining existing code fragments through indirect jumps and calls, without using the stack.
- libc: the standard C library, containing functions such as
system(). - Logic bug: a flaw in the program's rules rather than in its memory handling.
- max_allowed_packet: the largest single message the MariaDB server will accept.
- mmap: the system call that asks the operating system for a large block of memory.
- munmap: the system call that releases an mmap region.
- Offset: a distance, in bytes, from the start of a block or base address.
- PID 1: the first process started on a system or in a container; in a container, its exit stops the container.
- PIE (Position Independent Executable): a program whose code can be loaded at any address, with a base address chosen at runtime.
- Pointer: a memory address.
- Port: a numbered network door on a machine; MariaDB listens on 3306 by default.
- Primitive: a small capability an attacker can build on.
- Privilege escalation: gaining more permissions than you were given.
- Reentrancy: entering a piece of code again while it is still running.
- Register: a tiny, very fast storage slot inside the processor.
- ROP (Return-Oriented Programming): chaining existing code fragments by manipulating return addresses on the stack.
- secure_file_priv: a MariaDB setting that restricts which folders the server may read from or write to.
- SQL: the language used to talk to relational databases.
- Stack: the memory region where a program tracks which function called which and where to return.
- Stack canary: a secret value placed on the stack to detect tampering.
- Stack pivot: moving the stack pointer to memory the attacker controls.
- system(): the standard C library function that runs a shell command.
- TCP: the network protocol used to open a reliable connection between two computers.
- uid: the numeric identifier of a user on Linux.
- Upstream: the main project that publishes the software, as opposed to a copy or fork.
- USAGE-only: the weakest MariaDB privilege, allowing login and nothing else.
- Use-after-free: a memory bug where a program frees a block and then keeps using it.
- User variable: a named storage slot in a SQL session, written like
@name. - Vtable: a table of function addresses used to decide which function to call for an object.