Bug 2162056 (CVE-2022-41903)

Summary: CVE-2022-41903 git: Heap overflow in `git archive`, `git log --format` leading to RCE
Product: [Other] Security Response Reporter: Sandipan Roy <saroy>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: unspecifiedCC: aeladawy, arachman, chazlett, fhirtz, hhorak, jbilling, jorton, jwon, kyoshida, lveyde, michal.skrivanek, mperina, mvanderw, opohorel, pjindal, rdey, rpalathi, sbonazzo, security-response-team, wadeck.follonier
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
A flaw was found in Git, a distributed revision control system. This issue occurs due to an integer overflow in `pretty.c::format_and_pad_commit()`, where a `size_t` 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.
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-02-10 04:07:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2162059, 2162060, 2162061, 2162062, 2162063, 2162064, 2162065, 2162066, 2162067, 2162068, 2162069, 2162070, 2162071, 2184002    
Bug Blocks: 2161783    

Description Sandipan Roy 2023-01-18 17:01:57 UTC
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::format_and_pad_commit()` where a `size_t` 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`.

https://github.com/git/git/security/advisories/GHSA-475x-2q3q-hvwq
https://github.com/git/git/commit/508386c6c5857b4faa2c3e491f422c98cc69ae76
https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_export_subst
https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt-emltltNgttruncltruncmtruncem

Comment 1 Sandipan Roy 2023-01-18 17:24:31 UTC
Created git tracking bugs for this issue:

Affects: fedora-36 [bug 2162065]
Affects: fedora-37 [bug 2162066]

Comment 6 Wadeck 2023-02-03 10:46:04 UTC
Hello there,

If it's not the correct location for this comment, please redirect me to a better place ;-)

Do you have any ETA about the availability of the fix in the affected lines of your Docker images?

UBI 7-9 are affected since more than 2 weeks, usually you are providing the corrections in a very reactive (and appreciated) way, making this one a bit weird (along with CVE-2022-23521).
Also I saw that the score was moving from Critical to High and now back to Critical.

In the meantime, do you have a workaround recommendation?

Wadeck

Comment 10 errata-xmlrpc 2023-02-06 16:37:15 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections for Red Hat Enterprise Linux 7

Via RHSA-2023:0597 https://access.redhat.com/errata/RHSA-2023:0597

Comment 11 errata-xmlrpc 2023-02-06 16:42:05 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.4 Extended Update Support

Via RHSA-2023:0596 https://access.redhat.com/errata/RHSA-2023:0596

Comment 12 errata-xmlrpc 2023-02-06 16:42:15 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.1 Update Services for SAP Solutions

Via RHSA-2023:0599 https://access.redhat.com/errata/RHSA-2023:0599

Comment 13 errata-xmlrpc 2023-02-06 19:36:27 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.2 Advanced Update Support
  Red Hat Enterprise Linux 8.2 Update Services for SAP Solutions
  Red Hat Enterprise Linux 8.2 Telecommunications Update Service

Via RHSA-2023:0609 https://access.redhat.com/errata/RHSA-2023:0609

Comment 14 errata-xmlrpc 2023-02-06 19:39:23 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9

Via RHSA-2023:0611 https://access.redhat.com/errata/RHSA-2023:0611

Comment 15 errata-xmlrpc 2023-02-06 19:45:53 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2023:0610 https://access.redhat.com/errata/RHSA-2023:0610

Comment 16 errata-xmlrpc 2023-02-07 15:39:42 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9.0 Extended Update Support

Via RHSA-2023:0627 https://access.redhat.com/errata/RHSA-2023:0627

Comment 17 errata-xmlrpc 2023-02-07 15:47:46 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.6 Extended Update Support

Via RHSA-2023:0628 https://access.redhat.com/errata/RHSA-2023:0628

Comment 18 Product Security DevOps Team 2023-02-10 04:07:49 UTC
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s):

https://access.redhat.com/security/cve/cve-2022-41903

Comment 19 errata-xmlrpc 2023-02-28 09:19:53 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 7

Via RHSA-2023:0978 https://access.redhat.com/errata/RHSA-2023:0978

Comment 21 errata-xmlrpc 2023-04-10 01:30:27 UTC
This issue has been addressed in the following products:

  Red Hat Virtualization 4 for Red Hat Enterprise Linux 8

Via RHSA-2023:1677 https://access.redhat.com/errata/RHSA-2023:1677