🇰🇷 한글 설명
Git의 three-way merge 코드(xdiff)에서 힙 버퍼 오버플로우가 발생합니다. 공격자가 제어하는 저장소의 .gitattributes에 설정된 conflict-marker-size 값과 다수의 충돌을 이용해 32비트 정수가 래핑되면서 작은 버퍼를 넘어 쓰기가 발생합니다. 이로 인해 Git 충돌 또는 힙 손상이 일어날 수 있습니다.
💡 쉬운 설명
Git이 파일을 병합할 때 계산하는 크기 값이 너무 커지면서 메모리 경계를 넘어 데이터를 쓰게 됩니다. 악성 저장소를 병합하면 Git이 비정상 종료되거나 메모리가 손상될 수 있습니다.
🇺🇸 원문 (English)
Affected versions of Git have a heap buffer overflow in the three-way merge
code (xdiff), which an attacker can trigger through a repository they
control.
When Git merges a file, it first adds up the size of the merged
output, allocates a buffer of that size, and then writes the output into
it. That total was kept in a 32-bit signed integer. The
conflict-marker-size attribute, which can be set from a committed
.gitattributes file, accepts any positive integer, and the markers are
written several times for every conflict. A small file with a huge marker
size and many separate conflicts can therefore push the total past 4 GiB,
so the integer wraps to a small value and Git writes attacker-controlled
merge output past the end of a buffer that is too small. At minimum this
crashes Git, and because the overflow is large and its contents are largely
attacker-controlled, worse heap corruption is possible.
Any command that does a textual three-way merge can trigger it, such
as git-merge(1), git-rebase(1), git-cherry-pick(1), and
git-merge-tree(1). The latter is most likely a target for Git forges,
which might use git-merge-tree(1) on the server-side to check
mergeability. When the server reads attributes from trees in the
repository (for example through attr.tree or --attr-source), any
user who can push branches and request that they be merged (for
example by opening a pull or merge request) can trigger the overflow
without anyone else doing anything, and the data they push is small
because the oversized output only appears during the merge.
The problem has been patched by computing the size as size_t and
checking every addition for overflow, so Git stops with an error
instead of overflowing.
Servers that cannot upgrade right away can add
* conflict-marker-size=7
to each repository's info/attributes as a workaround, which overrides
any in-tree .gitattributes, or turn off server-side mergeability checks for
untrusted repositories.
📍 영향받는 시스템
Git 패치 이전 버전 (three-way merge를 수행하는 Git 및 이를 사용하는 Git 서버/포지)
⚔️ 공격 벡터
공격자가 조작한 .gitattributes(conflict-marker-size)와 다수의 충돌을 포함한 저장소를 push/merge 요청하여 서버나 사용자의 병합 작업을 유발
🛡️ 대응 방법
Git을 패치된 최신 버전으로 업데이트하고, 업데이트가 어려우면 info/attributes에 'conflict-marker-size=7'을 추가하거나 신뢰하지 않는 저장소의 서버 측 병합 가능성 검사를 끕니다.
🔧 검증 코드
출력된 git 버전을 패치된 최신 릴리스(벤더 보안 공지 기준)와 비교하고, conflict-marker 설정 유무를 확인합니다. 버전이 패치 이전이면 취약한 것으로 판단합니다.
git --version 2>/dev/null && git config --system --list 2>/dev/null | grep -i conflict || echo 'no system conflict-marker config'