Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
71e3b36
Add isolated MariaDB CONNECT CWE-134 validation harness
yunshingng Nov 15, 2026
c7a5baf
Add disposable MariaDB CONNECT test image
yunshingng Nov 15, 2026
5acb462
Configure CONNECT plugin for isolated validation
yunshingng Nov 15, 2026
6e5305b
Add disposable MariaDB test services
yunshingng Nov 15, 2026
7ef2461
Add end-to-end CONNECT format-string test runner
yunshingng Nov 15, 2026
81e2e74
Add CI workflow for MariaDB CONNECT CWE-134 validation
yunshingng Nov 15, 2026
c5f680f
Make CONNECT package prerequisite explicit
yunshingng Nov 15, 2026
2f01ca3
Use preloaded CONNECT plugin in SQL probe
yunshingng Nov 15, 2026
a2f2292
Run validation workflow for pull requests
yunshingng Nov 15, 2026
4e5c151
Document shell invocation accurately
yunshingng Nov 15, 2026
bfd6e4f
Fix TCP readiness and make SQL failures fail CI
yunshingng Nov 15, 2026
c2c5481
Document strict SQL validation and evidence limits
yunshingng Nov 15, 2026
f12b898
Assert expected fortified %n abort as DoS evidence
yunshingng Nov 15, 2026
dc8e601
Record reproduced MariaDB CONNECT %n denial of service
yunshingng Nov 15, 2026
7f5318e
Document MariaDB upstream confirmation of CONNECT format-string flaw
yunshingng Nov 15, 2026
73fa4cb
Document RCE assessment and fixed partname write target
yunshingng Nov 15, 2026
c2e27b2
Add isolated snprintf variadic-slot probe for CONNECT path
yunshingng Nov 15, 2026
dc4872f
Build test-only variadic argument probe into MariaDB test image
yunshingng Nov 15, 2026
03c0694
Add actual MariaDB variadic-slot probe case to E2E runner
yunshingng Nov 15, 2026
5c51902
Fix runner and add real CONNECT argument-slot probe case
yunshingng Nov 15, 2026
190c9bc
Quote percent positional probe string to prevent shell expansion
yunshingng Nov 15, 2026
8f01d65
Log memory mappings for MariaDB format-string variadic slots
yunshingng Nov 15, 2026
edd5ed7
Fix argument-slot probe assertion to validate emitted pointer map data
yunshingng Nov 15, 2026
2b48e15
Dump memory around writable variadic pointer targets in isolated probe
yunshingng Nov 15, 2026
82b6695
Capture post-format memory state and robustly detect writable mappings
yunshingng Nov 15, 2026
21dda14
Read mapped writable addresses directly for bounded memory inspection
yunshingng Nov 15, 2026
9d80c3c
Test bounded positional %hhn write through actual CONNECT call path
yunshingng Nov 15, 2026
5538e4c
Resolve CONNECT positional object pointer and vtable symbol
yunshingng Nov 15, 2026
ad2aaad
Label each CONNECT format callsite in the isolated ABI probe
yunshingng Nov 15, 2026
bcd8aad
Add partitioned OPTNAME ALTER path probe for alternate call context
yunshingng Nov 15, 2026
4d1942b
Fix optname probe runner status message
yunshingng Nov 15, 2026
8547b8f
Use CONNECT's actual XFILE_NAME option for index-option probe
yunshingng Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/mariadb-connect-cwe134.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: MariaDB CONNECT CWE-134 validation

on:
workflow_dispatch:
pull_request:
paths:
- "security-research/mariadb-connect-cwe134/**"
- ".github/workflows/mariadb-connect-cwe134.yml"
push:
paths:
- "security-research/mariadb-connect-cwe134/**"
- ".github/workflows/mariadb-connect-cwe134.yml"

jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- name: Build and run isolated MariaDB tests
working-directory: security-research/mariadb-connect-cwe134
run: |
chmod +x run.sh
./run.sh
- name: Upload test logs
if: always()
uses: actions/upload-artifact@v4
with:
name: mariadb-connect-cwe134-logs
path: security-research/mariadb-connect-cwe134/result-*.log
if-no-files-found: warn
12 changes: 12 additions & 0 deletions security-research/mariadb-connect-cwe134/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG MARIADB_IMAGE=mariadb:11.4
FROM ${MARIADB_IMAGE}

# Install CONNECT and a tiny, test-only ABI probe for the vulnerable call.
RUN apt-get update \
&& apt-get install -y --no-install-recommends mariadb-plugin-connect gcc libc6-dev \
&& rm -rf /var/lib/apt/lists/*

COPY connect.cnf /etc/mysql/conf.d/connect.cnf
COPY format_probe.c /tmp/format_probe.c
RUN gcc -shared -fPIC -O2 -o /usr/local/lib/libconnect_fmt_probe.so /tmp/format_probe.c -ldl \
&& rm -f /tmp/format_probe.c
58 changes: 58 additions & 0 deletions security-research/mariadb-connect-cwe134/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# MariaDB CONNECT CWE-134 validation harness

This directory is an isolated research harness. It does not modify Node.js runtime code.

## Reproduced result

On the GitHub Actions image tested on 2026-11-15:

- MariaDB: `11.4.13-MariaDB-ubu2404`
- CONNECT plugin: `1.07.0002`, status `ACTIVE`
- Baseline partitioned CONNECT CSV table: succeeds and returns the inserted row.
- Filename with extra `%s` conversions: CREATE/INSERT/SELECT completes; CONNECT emits a warning for the derived partition filename. No crash was observed.
- Filename containing `%n`: MariaDB prints `*** %n in writable segment detected ***`, aborts with signal 6, and the backtrace includes libc `__snprintf_chk` called from `ha_connect.so`.

The last case is a reproducible server-process denial of service on this tested build. The abort is caused by glibc fortification rejecting `%n`; this test does **not** show an arbitrary write or RCE.

## Independent upstream confirmation

MariaDB upstream committed [b01a176de5d4c814333fead0c85e431666e00fee](https://github.com/MariaDB/server/commit/b01a176de5d4c814333fead0c85e431666e00fee), titled:

`MDEV-41946 CONNECT: table option value used as printf format string, crash in ha_connect::GetRealString`

The commit message explicitly states that, for partitioned tables, `GetRealString()` and `FileExists()` passed option values as the `snprintf()` format string while substituting the partition name. The fix substitutes only the first literal `%s` and copies the remainder literally. The commit adds an upstream regression test using format tokens such as `%p`, `%d`, `%n`, and `%%`. This independently confirms the root cause and affected code path; it does not establish RCE.

## RCE assessment

A source-level review of the vulnerable call is important to avoid overstating impact:

- `GetRealString()` calls `snprintf(sv, size, s, partname)`: the attacker-controlled option supplies the format string, but the call supplies only one explicit variadic argument.
- In `ha_connect.h`, `partname` is an in-object `char partname[65]` buffer; `GetPartName()` returns that same buffer for partitioned tables.
- Consequently, a plain `%n` at the first conversion uses the supplied `partname` pointer as its destination. That is a fixed internal buffer, not an attacker-selected pointer. Other conversions that request additional arguments read arguments that were not supplied, which is undefined behavior but is not, by itself, proof of a controllable instruction pointer or RCE.
- The tested fortified build aborts on `%n` before a write occurs.

No controlled instruction pointer, executable memory, command execution, arbitrary-address write, or end-to-end RCE has been demonstrated for this specific MDEV-41946 path. RCE must therefore be treated as **unproven**, not as an established impact. A successful crash test and the upstream fix do not change that conclusion.

Do not conflate this finding with the older [CVE-2022-24051 / ZDI-22-318](https://www.zerodayinitiative.com/advisories/ZDI-22-318/), which is separately described by ZDI as a CONNECT format-string privilege-escalation issue with arbitrary code execution. That historical advisory does not prove that MDEV-41946 shares its exploit primitive or is exploitable in the same way.

## Run locally

Requirements: Docker Engine.

```sh
cd security-research/mariadb-connect-cwe134
bash run.sh
```

The runner waits for the final TCP listener (not the temporary socket-only initialization server), creates and selects a dedicated database, and asserts the baseline and extra-`%s` cases complete. For `%n`, it asserts the expected fortified abort signature and stopped server. Each test uses a disposable container and a test-only root password.

## Security interpretation

- Confirmed: SQL-controlled CONNECT `FILE_NAME` containing `%n` reaches `__snprintf_chk` through `ha_connect.so` and terminates MariaDB on the tested fortified build.
- Independently confirmed by MariaDB upstream: partition-name substitution passed table-option data as a printf format string; upstream fixed `GetRealString()` and `FileExists()` and added a regression test.
- Impact demonstrated: database server process crash / denial of service.
- Not demonstrated: arbitrary memory write, information disclosure, code execution, privilege escalation, or unauthenticated remote reachability.
- The test uses a privileged local database connection to create a partitioned CONNECT table. Exploitability depends on whether an attacker can obtain the required SQL privileges in a target deployment.
- Results apply only to the tested image and build configuration.

The safe implementation uses a constant format string and treats user-controlled option data literally, while preserving the intended first-`%s` partition substitution.
15 changes: 15 additions & 0 deletions security-research/mariadb-connect-cwe134/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
mariadb-connect:
build:
context: .
args:
MARIADB_IMAGE: ${MARIADB_IMAGE:-mariadb:11.4}
environment:
MARIADB_ROOT_PASSWORD: test-only-password
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 3s
timeout: 3s
retries: 40
tmpfs:
- /var/lib/mysql
2 changes: 2 additions & 0 deletions security-research/mariadb-connect-cwe134/connect.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mariadbd]
plugin_load_add=ha_connect
141 changes: 141 additions & 0 deletions security-research/mariadb-connect-cwe134/format_probe.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdarg.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

typedef int (*vsnprintf_chk_fn)(char *, size_t, int, size_t,
const char *, va_list);
static vsnprintf_chk_fn real_vsnprintf_chk;

static size_t append_text(char *dst, size_t pos, const char *src) {
while (*src && pos < 1900) dst[pos++] = *src++;
return pos;
}
static size_t append_hex(char *dst, size_t pos, uintptr_t value) {
static const char digits[] = "0123456789abcdef";
char tmp[2 * sizeof(value)];
size_t n = 0;
do { tmp[n++] = digits[value & 0xf]; value >>= 4; } while (value && n < sizeof(tmp));
if (pos < 1900) dst[pos++] = '0';
if (pos < 1900) dst[pos++] = 'x';
while (n && pos < 1900) dst[pos++] = tmp[--n];
return pos;
}
static void emit_map_and_memory(uintptr_t value, unsigned index) {
FILE *fp = fopen("/proc/self/maps", "r");
if (!fp) return;
char line[1024];
int writable = 0;
unsigned long lo = 0, hi = 0;
while (fgets(line, sizeof(line), fp)) {
unsigned long a = 0, b = 0;
if (sscanf(line, "%lx-%lx", &a, &b) == 2 && value >= a && value < b) {
lo = a; hi = b; char *perms = strchr(line, ' '); writable = perms && perms[2] == 'w';
char out[1200];
int n = snprintf(out, sizeof(out), "CONNECT_MAP arg%u=%s", index, line);
if (n > 0) (void)write(STDERR_FILENO, out, (size_t)n);
break;
}
}
fclose(fp);
if (!writable) return;
unsigned char bytes[96];
uintptr_t start = value >= lo + 32 ? value - 32 : lo;
size_t want = sizeof(bytes);
if (start + want > hi) want = hi - start;
memcpy(bytes, (const void *)start, want);
ssize_t got = (ssize_t)want;
if (got > 0) {
char out[1200];
size_t pos = 0;
pos = append_text(out, pos, "CONNECT_MEM arg");
char number[24];
int n = snprintf(number, sizeof(number), "%u addr=", index);
if (n > 0) pos = append_text(out, pos, number);
pos = append_hex(out, pos, start);
pos = append_text(out, pos, " bytes=");
static const char hx[] = "0123456789abcdef";
for (ssize_t i = 0; i < got && pos + 2 < sizeof(out); ++i) {
out[pos++] = hx[bytes[i] >> 4];
out[pos++] = hx[bytes[i] & 15];
}
out[pos++] = '\n';
(void)write(STDERR_FILENO, out, pos);
}
}

__attribute__((constructor))
static void init_real_vsnprintf_chk(void) {
real_vsnprintf_chk = (vsnprintf_chk_fn)dlsym(RTLD_NEXT, "__vsnprintf_chk");
}

int __snprintf_chk(char *dst, size_t maxlen, int flag, size_t objsize,
const char *format, ...) {
va_list ap;
va_start(ap, format);
if (format && strncmp(format, "PROBE_", 6) == 0) {
va_list scan;
uintptr_t values[12] = {0};
char line[2048];
size_t pos = 0;
va_copy(scan, ap);
pos = append_text(line, pos, "CONNECT_FMT_PROBE");
Dl_info caller_info;
if (dladdr(__builtin_return_address(0), &caller_info)) {
char caller[512];
int caller_len = snprintf(caller, sizeof(caller),
" caller=%s symbol=%s offset=%p",
caller_info.dli_fname ? caller_info.dli_fname : "?",
caller_info.dli_sname ? caller_info.dli_sname : "?",
(void *)((uintptr_t)__builtin_return_address(0) -
(uintptr_t)caller_info.dli_fbase));
if (caller_len > 0) pos = append_text(line, pos, caller);
}
for (unsigned i = 0; i < 12; ++i) {
values[i] = va_arg(scan, uintptr_t);
pos = append_text(line, pos, " arg");
char number[24];
int n = snprintf(number, sizeof(number), "%u=", i + 1);
if (n > 0) pos = append_text(line, pos, number);
pos = append_hex(line, pos, values[i]);
}
if (pos < sizeof(line)) line[pos++] = '\n';
(void)write(STDERR_FILENO, line, pos);
va_end(scan);
for (unsigned i = 0; i < 12; ++i) {
if (!values[i]) continue;
emit_map_and_memory(values[i], i + 1);
if (i == 4) {
uintptr_t first_word = *(const uintptr_t *)values[i];
Dl_info info;
if (dladdr((void *)first_word, &info)) {
char sym[1024];
int n = snprintf(sym, sizeof(sym),
"CONNECT_OBJECT arg5=%p first_word=%p image=%s symbol=%s\n",
(void *)values[i], (void *)first_word,
info.dli_fname ? info.dli_fname : "?",
info.dli_sname ? info.dli_sname : "?");
if (n > 0) (void)write(STDERR_FILENO, sym, (size_t)n);
}
}
}
int result = vsnprintf(dst, maxlen, format, ap);
for (unsigned i = 0; i < 12; ++i)
if (values[i]) emit_map_and_memory(values[i], i + 21);
va_end(ap);
return result;
}
if (real_vsnprintf_chk) {
int result = real_vsnprintf_chk(dst, maxlen, flag, objsize, format, ap);
va_end(ap);
return result;
}
int result = vsnprintf(dst, maxlen, format, ap);
va_end(ap);
return result;
}
Loading
Loading