CVE-2022-41903: Integer overflow in `git archive`, `git log --format` leading to RCE in git
A flaw was found in Git, a distributed revision control system. This issue occurs due to an integer overflow in pretty.c::formatandpadcommit(), where a sizet is stored improperly as an int, and then added as an offset to a memcpy(). This overflow can be triggered directly by a user running a command which invokes the commit formatting machinery (e.g., git log --format=...). It may also be triggered indirectly through the git archive via the export-subst mechanism, which expands format specifiers inside files within the repository during a git archive. This integer overflow can result in arbitrary heap writes, which may allow arbitrary code execution.
Other sources
Git is distributed revision control system. git log can display commits in an arbitrary format using its --format specifiers. This functionality is also exposed to git archive via the export-subst gitattribute. When processing the padding operators, there is a integer overflow in pretty.c::formatandpadcommit() where a sizet is stored improperly as an int, and then added as an offset to a memcpy(). This overflow can be triggered directly by a user running a command which invokes the commit formatting machinery (e.g., git log --format=...). It may also be triggered indirectly through git archive via the export-subst mechanism, which expands format specifiers inside of files within the repository during a git archive. This integer overflow can result in arbitrary heap writes, which may result in arbitrary code execution. The problem has been patched in the versions published on 2023-01-17, going back to v2.30.7. Users are advised to upgrade. Users who are unable to upgrade should disable git archive in untrusted repositories. If you expose git archive via git daemon, disable it by running git config --global daemon.uploadArch false.
The git-log command has the ability to display commits using an arbitrary format with its --format specifiers. This functionality is also exposed to git-archive via the export-subst gitattribute.
— GitLab
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:1.8.3.1-24.el7_9 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.31.1-3.el8_7 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.18.4-2.el8_1 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.18.4-3.el8_2 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.27.0-3.el8_4 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.31.1-3.el8_6 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.31.1-3.el9_1 - Upgrade
Upgrade
redhat/gitto a version that resolves this vulnerability.Fixed in 0:2.31.1-3.el9_0 - Upgrade
Upgrade
redhat/rh-git227-gitto a version that resolves this vulnerability.Fixed in 0:2.27.0-4.el7 - Upgrade
Upgrade
git/gitto a version that resolves this vulnerability.Fixed in 2.30.7 - Configuration
Disable exposing git archive via `git daemon` by setting `daemon.uploadArch` to `false` (run: `git config --global daemon.uploadArch false`).
Git (git daemon) daemon.uploadArch = false
Event History
Parent advisories
This vulnerability appears in the following advisories.
Frequently Asked Questions
What is CVE-2022-41903?
CVE-2022-41903 is a flaw found in Git, a distributed revision control system, that occurs due to an integer overflow in pretty.c.
How does CVE-2022-41903 affect Git?
CVE-2022-41903 affects Git by causing an integer overflow when processing the padding operators in the --format specifiers of git log and git archive.
What is the severity of CVE-2022-41903?
CVE-2022-41903 has a severity level of 9.8 (critical).
Which versions of Git are affected by CVE-2022-41903?
Git versions 1.8.3.1-24.el7_9 to 2.39.0 are affected by CVE-2022-41903.
How can I fix CVE-2022-41903?
To fix CVE-2022-41903, update Git to a version that includes the necessary security patches.