CVE-2026-85746 CRITICAL 9.9 난이도Difficulty 중급Intermediate

MariaDB ST_AsText 중첩 GeometryCollection 출력 버퍼 오버플로MariaDB ST_AsText output-buffer overflow on nested GeometryCollections

공식 참조Official references: NVDCVE.org

CVE-2026-85746는 MariaDB Server의 Out-of-bounds Write(CWE-787) 취약점으로, CVSS 9.9(CRITICAL)입니다. 영향 버전: 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1. 수정 버전: 10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2.CVE-2026-85746 is an Out-of-bounds Write (CWE-787) vulnerability in MariaDB Server, rated CVSS 9.9 (CRITICAL). Affected: 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1. Fixed in: 10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2.

제품Product MariaDB Server
영향 버전Affected 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1
수정 버전Fixed in 10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2
심각도Severity CVSS 9.9 CRITICAL
취약점 유형Weakness CWE-787 Out-of-bounds Write
공격 조건Attack conditions 원격 (네트워크) · 일반 권한 계정 필요 · 사용자 상호작용 불필요Remote (network) · Low-privilege account · No user interaction

1. TL;DR

  • MariaDB의 ST_AsText()(WKT 변환)가 GeometryCollection을 깊게 중첩한 입력을 처리할 때 출력 버퍼 바깥에 쓸 수 있습니다. 근거는 벤더 어드바이저리입니다.
  • 원인은 재귀 직렬화 과정에서 이미 쓴 바이트 수를 반영하지 않고, 용량 검사가 없는 qs_append로 뒤에 )를 덧붙이는 것입니다. 수정 커밋 메시지에 따르면 Gis_geometry_collection::get_data_as_wkt()는 공간을 따로 예약하지도 않았습니다.
  • 영향 버전은 어드바이저리 기준으로 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1입니다. 수정 버전은 10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2입니다.
  • 어드바이저리에 따르면 우회 방법은 없고 즉시 업그레이드해야 합니다. 코드 실행은 NVD와 어드바이저리 모두 “다른 취약점과 결합할 경우”라는 조건을 붙였습니다.

2. Flaw 분류

항목값
1차 CWECWE-787 Out-of-bounds Write (NVD 기준)
공격 벡터네트워크. 낮은 권한의 DB 계정이 조작된 GIS 객체를 서버에 제출 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H, 9.9)
영향힙 메모리 손상. NVD는 다른 취약점과 결합하면 코드 실행에 이를 수 있다고 설명. 단독으로 원격 코드 실행이 가능하다는 공개 근거는 확인되지 않음
전제영향 버전의 MariaDB 서버, SQL로 ST_AsText() 등 WKT 변환 경로에 조작된 GIS 값을 넘길 수 있는 계정(PR:L)

3. 근본 원인

배경: WKT 직렬화와 “빠른 추가”

공간 데이터(WKB)를 사람이 읽는 WKT 문자열로 바꾸는 코드는 sql/spatial.cc에 있습니다. 진입점은 Geometry::as_wkt()이고, 도형 종류별 get_data_as_wkt()가 실제 변환을 맡습니다. GeometryCollection은 다른 도형을 담을 수 있어서 안쪽 도형의 변환 함수를 재귀적으로 부릅니다.

MariaDB의 String 계열에는 append()와 qs_append()가 있습니다. 커밋 diff의 주석과 이슈 제목에 있는 assert(str_length + 1 <= Alloced_length)를 보면, qs_append()는 이미 충분한 공간이 확보되어 있다고 가정하고 쓰는 함수입니다. 용량이 모자라면 디버그 빌드에서는 assert로 멈추고, 릴리스 빌드에서 어떻게 동작하는지는 공개 정보로 확인되지 않았습니다. 반면 append()는 필요하면 버퍼를 늘립니다. 이 설명은 커밋 주석에서 읽어 낸 것이며, 클래스 정의는 직접 확인하지 않았습니다.

무엇이 잘못되었나

수정 커밋 메시지는 두 가지를 지적합니다.

  1. Geometry::as_wkt()가 재귀 호출 get_data_as_wkt()에서 결과 문자열에 써 넣은 바이트 수를 고려하지 않았습니다.
  2. Gis_geometry_collection::get_data_as_wkt()는 공간을 전혀 예약하지 않았습니다.

결과적으로 “처음에 계산해 둔 여유”를 중첩된 호출이 다 써 버린 뒤에도, 바깥 호출은 여유가 남아 있다고 믿고 )를 용량 검사 없이 붙였습니다. 중첩이 깊을수록 소비량이 커지므로, 컬렉션을 깊게 중첩한 입력이 버퍼를 넘기게 됩니다. NVD 설명도 같은 원리로 서술합니다(재귀 직렬화가 소비한 바이트를 반영하지 않고 충분한 공간을 예약하지 않는다는 내용).

핵심은 **“한 번 계산한 용량 예산을 재귀 호출 전체가 공유하는데, 소비량을 다시 확인하지 않는 것”**입니다.

4. 익스플로잇 흐름(개념)

공격 입력의 구체적 형태는 의도적으로 적지 않습니다. 개념 흐름은 다음과 같습니다.

  1. 조작된 GIS 값 제출 — 깊게 중첩된 GeometryCollection
  2. WKT 변환 호출 — ST_AsText
  3. 재귀 직렬화 — 소비한 바이트가 예산에 반영되지 않음
  4. 검사 없는 추가로 버퍼 밖 쓰기
  5. 힙 메모리 손상 — 다른 취약점과 결합 시 코드 실행 가능성
개념 흐름도 — 실행 가능한 페이로드가 아닙니다
  1. 낮은 권한의 계정이 WKB로 해석되는 값을 만듭니다. 이 값은 다른 컬렉션을 담은 컬렉션이 여러 겹 이어진 구조입니다.
  2. 서버가 이 값을 ST_AsText()로 문자열화합니다.
  3. 재귀 중에 출력 문자열이 커지지만, 초기에 잡은 여유 공간은 갱신되지 않거나 애초에 예약되지 않습니다.
  4. 용량 검사가 없는 qs_append() 경로가 할당 크기를 넘어 씁니다.
  5. 어드바이저리는 이 결함이 다른 취약점과 함께 쓰이는 다단계 체인의 일부가 될 수 있다고 설명합니다. 쓰기 내용과 위치를 공격자가 얼마나 제어할 수 있는지는 공개 정보로 확인되지 않았습니다.

5. 트리거 조건

  • 버전: 어드바이저리 기준 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1. NVD의 표기와 Jira의 Affects Version이 일부 다르므로 REVIEW_NOTES를 참고하세요.
  • 권한: CVSS는 PR:L이므로 SQL을 실행할 수 있는 낮은 권한의 계정이 필요합니다. 인증 없이 도달 가능하다는 근거는 확인되지 않았습니다.
  • 입력: 중첩이 깊은 GeometryCollection. 필요한 중첩 깊이의 임계값은 공개 출처에서 별도로 정리되어 있지 않아, 여기에는 적지 않았습니다.
  • 경로: 어드바이저리 제목과 NVD는 ST_AsText()를 지목합니다. 같은 as_wkt() 경로를 쓰는 다른 함수(예: AsText 별칭)가 영향받는지는 공개 정보로 확인되지 않았습니다.
  • 발견 경위: Jira에는 Sylvie Mayer가 보고했고 디버그 assert로 드러났다고 기록되어 있습니다.

6. 패치 분석

실제 패치 diff를 확인했습니다(커밋 5c04ca5, 3개 파일, 13줄 추가·3줄 삭제). 이 중 sql/spatial.cc의 변경은 qs_append를 append로 바꾼 3줄입니다. 나머지는 회귀 테스트(mysql-test/main/gis.test, gis.result)입니다.

+1−1c
if (get_class_info() != &geometrycollection_class)
  wkt->qs_append(')');
  wkt->append(')'); // NOT qs_append, get_data_as_wkt consumed reserved space
return 0;

Geometry::as_wkt()는 도형 본문을 get_data_as_wkt()로 쓴 뒤 닫는 괄호를 붙입니다. 이 시점에 앞선 호출이 이미 예약 공간을 소비했을 수 있으므로, 용량을 확인하지 않는 qs_append 대신 필요하면 버퍼를 늘리는 append를 씁니다. 커밋 주석이 이 이유를 직접 설명합니다.

+1−1c
  txt->qs_append('(');
  txt->append('(');
  while (n_objects--)
+1−1c
  txt->qs_append(')');
  txt->append(')');
exit:

두 변경은 Gis_geometry_collection::get_data_as_wkt() 안의 여는 괄호와 닫는 괄호입니다. 같은 컬렉션 안에서 자식을 재귀 처리하면서 공간이 줄어들 수 있으므로 용량 검사가 있는 경로로 바꿨습니다. 같은 함수의 구분자 추가(txt->append(STRING_WITH_LEN(","), 512))는 원래부터 append였고 이번에 바뀌지 않았습니다.

이 패치는 “필요한 크기를 정확히 계산해 한 번에 예약”하는 방식이 아니라, 검사 없는 쓰기를 검사 있는 쓰기로 바꿔 흐름을 끊는 방식입니다. 이 해석은 diff와 커밋 메시지에서 읽은 것이며, 이 외에 크기 계산 로직이 바뀐 곳은 확인되지 않았습니다. 일반론으로는, 재귀 구조에서 “이전에 확보해 둔 용량”에 기대는 qs_* 계열 호출이 남아 있으면 같은 유형의 결함이 재발할 수 있습니다.

7. 탐지·완화

즉시 조치

  • 어드바이저리에 따르면 우회 방법이 없으므로, 수정 버전(10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2)으로 업그레이드하세요. 10.6은 Jira에 EOL로 표시되어 있으니 지원 중인 시리즈로 옮기는 계획도 함께 세우세요.
  • 외부 입력이 SQL에 흘러드는 애플리케이션은 DB 계정 권한을 최소화하세요. 이 취약점은 SQL 실행 권한이 있는 계정이 필요합니다.
  • GIS 함수를 쓰지 않는 계정이나 서비스는 DB 접근 범위를 줄이세요. 이는 일반적인 노출 축소이며 벤더가 권고한 우회책은 아닙니다.

탐지

  • 쿼리 로그나 감사 로그에서 공간 함수(ST_AsText, AsText 등)에 비정상적으로 큰 입력이 들어가는지 살펴보세요.
  • 서버가 반복적으로 비정상 종료되거나 재시작하는지 확인하세요. 공개 정보로는 릴리스 빌드에서 어떤 증상이 나타나는지 확인되지 않았으므로, 크래시만이 유일한 징후라고 가정하지 마세요.
  • 인스턴스 버전을 목록화해 위 영향 범위와 대조하세요.

격리된 실습(로컬 Docker 랩)

  • 재현과 분석은 인터넷과 분리된 로컬 Docker 랩에서만 하세요. 외부망에 닿는 네트워크 설정, 공유 볼륨, 실서비스 데이터는 연결하지 마세요.
  • 영향 버전과 수정 버전을 각각 컨테이너로 띄워 동작 차이를 비교하는 방식을 권합니다. 디버그 빌드는 qs_append assert로 실패 지점을 쉽게 볼 수 있습니다.
  • 이 글은 공격 입력을 제공하지 않습니다. 공개된 회귀 테스트나 Jira의 입력은 직접 확인하되, 랩 밖으로 가져가거나 타인의 시스템에 사용하지 마세요.
  • 학습 목표는 “예산 계산이 재귀를 따라가지 못할 때 어떤 일이 생기는가”를 소스와 diff로 읽는 것입니다.

8. References

1. TL;DR

  • MariaDB’s ST_AsText() (WKT conversion) can write outside the output buffer when it processes deeply nested GeometryCollection input. The basis is the vendor advisory.
  • The cause is that during recursive serialization it appends a trailing ) with qs_append, which has no capacity check and does not account for bytes already written. According to the fix commit message, Gis_geometry_collection::get_data_as_wkt() did not reserve space either.
  • Per the advisory, affected versions are 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1. Fixed versions are 10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2.
  • The advisory says there is no workaround and you must upgrade immediately. Both NVD and the advisory qualify code execution as something that requires “being combined with another vulnerability.”

2. Flaw classification

ItemValue
Primary CWECWE-787 Out-of-bounds Write (per NVD)
Attack vectorNetwork. A low-privilege DB account submits a crafted GIS object to the server (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H, 9.9)
ImpactHeap memory corruption. NVD explains it can lead to code execution when combined with another vulnerability. There is no public evidence that remote code execution is possible on its own
PrerequisitesAn affected MariaDB server, and an account (PR:L) that can pass a crafted GIS value into a WKT-conversion path such as ST_AsText() via SQL

3. Root cause

Background: WKT serialization and the “quick append”

The code that turns spatial data (WKB) into a human-readable WKT string lives in sql/spatial.cc. The entry point is Geometry::as_wkt(), and a per-geometry get_data_as_wkt() does the actual conversion. A GeometryCollection can contain other geometries, so it calls the inner geometries’ conversion functions recursively.

MariaDB’s String family has append() and qs_append(). From the comment in the commit diff and the assert in the issue title (str_length + 1 <= Alloced_length), qs_append() is a function that writes while assuming enough space has already been reserved. If capacity is short, it stops at the assert in a debug build; how it behaves in a release build is not confirmed in public sources. append(), by contrast, grows the buffer when needed. This description is read from the commit comments; the class definition was not checked directly.

What went wrong

The fix commit message points out two things:

  1. Geometry::as_wkt() did not account for the number of bytes written into the result string by the recursive get_data_as_wkt() calls.
  2. Gis_geometry_collection::get_data_as_wkt() reserved no space at all.

As a result, even after nested calls had used up “the headroom computed at the start,” the outer call believed headroom remained and appended ) without a capacity check. The deeper the nesting, the greater the consumption, so input with a deeply nested collection overruns the buffer. The NVD description states the same principle (that recursive serialization does not account for consumed bytes and does not reserve enough space).

The core issue is “a capacity budget computed once is shared across the entire recursion, but consumption is never re-checked.”

4. Exploit flow (conceptual)

The concrete shape of the attack input is deliberately omitted. The conceptual flow is:

  1. Submit crafted GIS value — deeply nested GeometryCollection
  2. WKT conversion call — ST_AsText
  3. Recursive serialization — consumed bytes not reflected in the budget
  4. Unchecked append writes past the buffer
  5. Heap memory corruption — possible code execution if combined with another vulnerability
Conceptual flow — not an executable payload
  1. A low-privilege account crafts a value interpreted as WKB. This value is a structure of collections nested several layers deep, each holding another collection.
  2. The server stringifies this value with ST_AsText().
  3. During recursion the output string grows, but the headroom reserved at the start is not updated, or was never reserved to begin with.
  4. The capacity-unchecked qs_append() path writes beyond the allocated size.
  5. The advisory explains this flaw can be part of a multi-stage chain used together with other vulnerabilities. How much the attacker can control the written content and location is not confirmed in public sources.

5. Trigger conditions

  • Version: per the advisory, 10.6.1–10.6.27, 10.11.1–10.11.18, 11.4.1–11.4.12, 11.8.1–11.8.8, 12.3.1–12.3.2, 13.0.1. NVD’s notation and Jira’s Affects Version differ in places, so see REVIEW_NOTES.
  • Privileges: CVSS is PR:L, so a low-privilege account that can run SQL is needed. There is no evidence it is reachable without authentication.
  • Input: a deeply nested GeometryCollection. The threshold nesting depth required is not separately documented in public sources, so it is not stated here.
  • Path: the advisory title and NVD point to ST_AsText(). Whether other functions that use the same as_wkt() path (for example the AsText alias) are affected is not confirmed in public sources.
  • Discovery: Jira records that Sylvie Mayer reported it and that it surfaced via a debug assert.

6. Patch analysis

The actual patch diff was reviewed (commit 5c04ca5, 3 files, 13 additions / 3 deletions). Of these, the change in sql/spatial.cc is 3 lines replacing qs_append with append. The rest are regression tests (mysql-test/main/gis.test, gis.result).

+1−1c
if (get_class_info() != &geometrycollection_class)
  wkt->qs_append(')');
  wkt->append(')'); // NOT qs_append, get_data_as_wkt consumed reserved space
return 0;

Geometry::as_wkt() writes the geometry body with get_data_as_wkt() and then appends the closing parenthesis. By this point a prior call may already have consumed the reserved space, so instead of the capacity-unchecked qs_append it uses append, which grows the buffer when needed. The commit comment explains this reason directly.

+1−1c
  txt->qs_append('(');
  txt->append('(');
  while (n_objects--)
+1−1c
  txt->qs_append(')');
  txt->append(')');
exit:

These two changes are the opening and closing parentheses inside Gis_geometry_collection::get_data_as_wkt(). Because space can shrink while recursively processing children within the same collection, they were switched to the capacity-checked path. The separator append in the same function (txt->append(STRING_WITH_LEN(","), 512)) was already append and was not changed this time.

This patch does not “compute the exact needed size and reserve it all at once”; it breaks the chain by replacing unchecked writes with checked writes. This reading comes from the diff and the commit message; no other change to size-calculation logic was confirmed. In general, if qs_*-family calls that rely on “previously reserved capacity” remain in a recursive structure, the same class of flaw can recur.

7. Detection & mitigation

Immediate actions

  • Since the advisory says there is no workaround, upgrade to a fixed version (10.6.28, 10.11.19, 11.4.13, 11.8.9, 12.3.3, 13.0.2). 10.6 is marked EOL in Jira, so also plan to move to a supported series.
  • For applications where external input flows into SQL, minimize DB account privileges. This vulnerability requires an account with SQL-execution privilege.
  • For accounts or services that don’t use GIS functions, reduce their DB access scope. This is general exposure reduction, not a vendor-recommended workaround.

Detection

  • Look in query logs or audit logs for abnormally large input going into spatial functions (ST_AsText, AsText, etc.).
  • Check whether the server repeatedly crashes or restarts. Public sources don’t confirm the symptoms in a release build, so do not assume a crash is the only sign.
  • Inventory your instance versions and compare them against the affected range above.

Isolated practice (local Docker lab)

  • Reproduce and analyze only in a local Docker lab isolated from the internet. Do not connect any network setting that reaches external networks, shared volumes, or real service data.
  • We recommend bringing up an affected version and a fixed version each in a container and comparing the behavioral difference. A debug build makes the failure point easy to see via the qs_append assert.
  • This write-up does not provide attack input. Check the public regression tests or the Jira input directly, but do not take them outside the lab or use them against others’ systems.
  • The learning goal is to read, from the source and the diff, “what happens when budget accounting can’t keep up with recursion.”

8. References