Skip to content

Arbitrary code execution due to heap corruption in `git_index_add`

High
ethomson published GHSA-j2v7-4f6v-gpg8 Feb 6, 2024

Package

libgit2 (C)

Affected versions

< 1.6.5
< 1.7.2

Patched versions

1.6.5
1.7.2

Description

Impact

Using well-crafted inputs to git_index_add can cause heap corruption that could be leveraged for arbitrary code execution.

Detailed description

There is an issue in the has_dir_name function in src/libgit2/index.c, which frees an entry that should not be freed. The freed entry is later used and overwritten with potentially bad actor-controlled data leading to controlled heap corruption. Depending on the application that uses libgit2, this could lead to arbitrary code execution.

To trigger the problem, the bad actor must be able to trigger two consecutive calls to git_index_add with a filename that starts with a / character. To control the heap corruption, the bad actor must be able to control the ctime field of the git_index_entry data structure.

Patches

Users should upgrade to v1.6.5 or v1.7.2.

Workarounds

Prevent paths beginning with / from being provided to git_index_add.

Severity

High

CVE ID

CVE-2024-24577

Weaknesses

No CWEs