Skip to content

Commit a7237f5

Browse files
committed
Sync with 2.33.7
* maint-2.33: Git 2.33.7 Git 2.32.6 Git 2.31.7 Git 2.30.8 apply: fix writing behind newly created symbolic links dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS clone: delay picking a transport until after get_repo_path() t5619: demonstrate clone_local() with ambiguous transport
2 parents bd6d3de + ed4404a commit a7237f5

12 files changed

+309
-9
lines changed

Documentation/RelNotes/2.30.8.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Git v2.30.8 Release Notes
2+
=========================
3+
4+
This release addresses the security issues CVE-2023-22490 and
5+
CVE-2023-23946.
6+
7+
8+
Fixes since v2.30.7
9+
-------------------
10+
11+
* CVE-2023-22490:
12+
13+
Using a specially-crafted repository, Git can be tricked into using
14+
its local clone optimization even when using a non-local transport.
15+
Though Git will abort local clones whose source $GIT_DIR/objects
16+
directory contains symbolic links (c.f., CVE-2022-39253), the objects
17+
directory itself may still be a symbolic link.
18+
19+
These two may be combined to include arbitrary files based on known
20+
paths on the victim's filesystem within the malicious repository's
21+
working copy, allowing for data exfiltration in a similar manner as
22+
CVE-2022-39253.
23+
24+
* CVE-2023-23946:
25+
26+
By feeding a crafted input to "git apply", a path outside the
27+
working tree can be overwritten as the user who is running "git
28+
apply".
29+
30+
* A mismatched type in `attr.c::read_attr_from_index()` which could
31+
cause Git to errantly reject attributes on Windows and 32-bit Linux
32+
has been corrected.
33+
34+
Credit for finding CVE-2023-22490 goes to yvvdwf, and the fix was
35+
developed by Taylor Blau, with additional help from others on the
36+
Git security mailing list.
37+
38+
Credit for finding CVE-2023-23946 goes to Joern Schneeweisz, and the
39+
fix was developed by Patrick Steinhardt.
40+
41+
42+
Johannes Schindelin (1):
43+
attr: adjust a mismatched data type
44+
45+
Patrick Steinhardt (1):
46+
apply: fix writing behind newly created symbolic links
47+
48+
Taylor Blau (3):
49+
t5619: demonstrate clone_local() with ambiguous transport
50+
clone: delay picking a transport until after get_repo_path()
51+
dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
52+

Documentation/RelNotes/2.31.7.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Git v2.31.7 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.8 to
5+
address the security issues CVE-2023-22490 and CVE-2023-23946;
6+
see the release notes for that version for details.

Documentation/RelNotes/2.32.6.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Git v2.32.6 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.8 and v2.31.7
5+
to address the security issues CVE-2023-22490 and CVE-2023-23946;
6+
see the release notes for these versions for details.

Documentation/RelNotes/2.33.7.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Git v2.33.7 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.8, v2.31.7
5+
and v2.32.6 to address the security issues CVE-2023-22490 and
6+
CVE-2023-23946; see the release notes for these versions for
7+
details.

apply.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4424,6 +4424,33 @@ static int create_one_file(struct apply_state *state,
44244424
if (state->cached)
44254425
return 0;
44264426

4427+
/*
4428+
* We already try to detect whether files are beyond a symlink in our
4429+
* up-front checks. But in the case where symlinks are created by any
4430+
* of the intermediate hunks it can happen that our up-front checks
4431+
* didn't yet see the symlink, but at the point of arriving here there
4432+
* in fact is one. We thus repeat the check for symlinks here.
4433+
*
4434+
* Note that this does not make the up-front check obsolete as the
4435+
* failure mode is different:
4436+
*
4437+
* - The up-front checks cause us to abort before we have written
4438+
* anything into the working directory. So when we exit this way the
4439+
* working directory remains clean.
4440+
*
4441+
* - The checks here happen in the middle of the action where we have
4442+
* already started to apply the patch. The end result will be a dirty
4443+
* working directory.
4444+
*
4445+
* Ideally, we should update the up-front checks to catch what would
4446+
* happen when we apply the patch before we damage the working tree.
4447+
* We have all the information necessary to do so. But for now, as a
4448+
* part of embargoed security work, having this check would serve as a
4449+
* reasonable first step.
4450+
*/
4451+
if (path_is_beyond_symlink(state, path))
4452+
return error(_("affected file '%s' is beyond a symbolic link"), path);
4453+
44274454
res = try_create_file(state, path, mode, buf, size);
44284455
if (res < 0)
44294456
return -1;

builtin/clone.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,10 +1112,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11121112
refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix,
11131113
branch_top.buf);
11141114

1115-
transport = transport_get(remote, remote->url[0]);
1116-
transport_set_verbosity(transport, option_verbosity, option_progress);
1117-
transport->family = family;
1118-
11191115
path = get_repo_path(remote->url[0], &is_bundle);
11201116
is_local = option_local != 0 && path && !is_bundle;
11211117
if (is_local) {
@@ -1137,6 +1133,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11371133
}
11381134
if (option_local > 0 && !is_local)
11391135
warning(_("--local is ignored"));
1136+
1137+
transport = transport_get(remote, path ? path : remote->url[0]);
1138+
transport_set_verbosity(transport, option_verbosity, option_progress);
1139+
transport->family = family;
11401140
transport->cloning = 1;
11411141

11421142
transport_set_option(transport, TRANS_OPT_KEEP, "yes");

dir-iterator.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct dir_iterator *dir_iterator_begin(const char *path, unsigned int flags)
203203
{
204204
struct dir_iterator_int *iter = xcalloc(1, sizeof(*iter));
205205
struct dir_iterator *dir_iterator = &iter->base;
206-
int saved_errno;
206+
int saved_errno, err;
207207

208208
strbuf_init(&iter->base.path, PATH_MAX);
209209
strbuf_addstr(&iter->base.path, path);
@@ -213,10 +213,15 @@ struct dir_iterator *dir_iterator_begin(const char *path, unsigned int flags)
213213
iter->flags = flags;
214214

215215
/*
216-
* Note: stat already checks for NULL or empty strings and
217-
* inexistent paths.
216+
* Note: stat/lstat already checks for NULL or empty strings and
217+
* nonexistent paths.
218218
*/
219-
if (stat(iter->base.path.buf, &iter->base.st) < 0) {
219+
if (iter->flags & DIR_ITERATOR_FOLLOW_SYMLINKS)
220+
err = stat(iter->base.path.buf, &iter->base.st);
221+
else
222+
err = lstat(iter->base.path.buf, &iter->base.st);
223+
224+
if (err < 0) {
220225
saved_errno = errno;
221226
goto error_out;
222227
}

dir-iterator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
* not the symlinks themselves, which is the default behavior. Broken
6262
* symlinks are ignored.
6363
*
64+
* Note: setting DIR_ITERATOR_FOLLOW_SYMLINKS affects resolving the
65+
* starting path as well (e.g., attempting to iterate starting at a
66+
* symbolic link pointing to a directory without FOLLOW_SYMLINKS will
67+
* result in an error).
68+
*
6469
* Warning: circular symlinks are also followed when
6570
* DIR_ITERATOR_FOLLOW_SYMLINKS is set. The iteration may end up with
6671
* an ELOOP if they happen and DIR_ITERATOR_PEDANTIC is set.

t/t0066-dir-iterator.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ test_expect_success SYMLINKS 'setup dirs with symlinks' '
110110
mkdir -p dir5/a/c &&
111111
ln -s ../c dir5/a/b/d &&
112112
ln -s ../ dir5/a/b/e &&
113-
ln -s ../../ dir5/a/b/f
113+
ln -s ../../ dir5/a/b/f &&
114+
115+
ln -s dir4 dir6
114116
'
115117

116118
test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default' '
@@ -146,4 +148,27 @@ test_expect_success SYMLINKS 'dir-iterator should follow symlinks w/ follow flag
146148
test_cmp expected-follow-sorted-output actual-follow-sorted-output
147149
'
148150

151+
test_expect_success SYMLINKS 'dir-iterator does not resolve top-level symlinks' '
152+
test_must_fail test-tool dir-iterator ./dir6 >out &&
153+
154+
grep "ENOTDIR" out
155+
'
156+
157+
test_expect_success SYMLINKS 'dir-iterator resolves top-level symlinks w/ follow flag' '
158+
cat >expected-follow-sorted-output <<-EOF &&
159+
[d] (a) [a] ./dir6/a
160+
[d] (a/f) [f] ./dir6/a/f
161+
[d] (a/f/c) [c] ./dir6/a/f/c
162+
[d] (b) [b] ./dir6/b
163+
[d] (b/c) [c] ./dir6/b/c
164+
[f] (a/d) [d] ./dir6/a/d
165+
[f] (a/e) [e] ./dir6/a/e
166+
EOF
167+
168+
test-tool dir-iterator --follow-symlinks ./dir6 >out &&
169+
sort out >actual-follow-sorted-output &&
170+
171+
test_cmp expected-follow-sorted-output actual-follow-sorted-output
172+
'
173+
149174
test_done

t/t4115-apply-symlink.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,85 @@ test_expect_success 'apply --index symlink patch' '
4444
4545
'
4646

47+
test_expect_success 'symlink setup' '
48+
ln -s .git symlink &&
49+
git add symlink &&
50+
git commit -m "add symlink"
51+
'
52+
53+
test_expect_success SYMLINKS 'symlink escape when creating new files' '
54+
test_when_finished "git reset --hard && git clean -dfx" &&
55+
56+
cat >patch <<-EOF &&
57+
diff --git a/symlink b/renamed-symlink
58+
similarity index 100%
59+
rename from symlink
60+
rename to renamed-symlink
61+
--
62+
diff --git /dev/null b/renamed-symlink/create-me
63+
new file mode 100644
64+
index 0000000..039727e
65+
--- /dev/null
66+
+++ b/renamed-symlink/create-me
67+
@@ -0,0 +1,1 @@
68+
+busted
69+
EOF
70+
71+
test_must_fail git apply patch 2>stderr &&
72+
cat >expected_stderr <<-EOF &&
73+
error: affected file ${SQ}renamed-symlink/create-me${SQ} is beyond a symbolic link
74+
EOF
75+
test_cmp expected_stderr stderr &&
76+
! test_path_exists .git/create-me
77+
'
78+
79+
test_expect_success SYMLINKS 'symlink escape when modifying file' '
80+
test_when_finished "git reset --hard && git clean -dfx" &&
81+
touch .git/modify-me &&
82+
83+
cat >patch <<-EOF &&
84+
diff --git a/symlink b/renamed-symlink
85+
similarity index 100%
86+
rename from symlink
87+
rename to renamed-symlink
88+
--
89+
diff --git a/renamed-symlink/modify-me b/renamed-symlink/modify-me
90+
index 1111111..2222222 100644
91+
--- a/renamed-symlink/modify-me
92+
+++ b/renamed-symlink/modify-me
93+
@@ -0,0 +1,1 @@
94+
+busted
95+
EOF
96+
97+
test_must_fail git apply patch 2>stderr &&
98+
cat >expected_stderr <<-EOF &&
99+
error: renamed-symlink/modify-me: No such file or directory
100+
EOF
101+
test_cmp expected_stderr stderr &&
102+
test_must_be_empty .git/modify-me
103+
'
104+
105+
test_expect_success SYMLINKS 'symlink escape when deleting file' '
106+
test_when_finished "git reset --hard && git clean -dfx && rm .git/delete-me" &&
107+
touch .git/delete-me &&
108+
109+
cat >patch <<-EOF &&
110+
diff --git a/symlink b/renamed-symlink
111+
similarity index 100%
112+
rename from symlink
113+
rename to renamed-symlink
114+
--
115+
diff --git a/renamed-symlink/delete-me b/renamed-symlink/delete-me
116+
deleted file mode 100644
117+
index 1111111..0000000 100644
118+
EOF
119+
120+
test_must_fail git apply patch 2>stderr &&
121+
cat >expected_stderr <<-EOF &&
122+
error: renamed-symlink/delete-me: No such file or directory
123+
EOF
124+
test_cmp expected_stderr stderr &&
125+
test_path_is_file .git/delete-me
126+
'
127+
47128
test_done

t/t5604-clone-reference.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,20 @@ test_expect_success SYMLINKS 'clone repo with symlinked or unknown files at obje
344344
test_must_be_empty T--shared.objects-symlinks.raw
345345
'
346346

347+
test_expect_success SYMLINKS 'clone repo with symlinked objects directory' '
348+
test_when_finished "rm -fr sensitive malicious" &&
349+
350+
mkdir -p sensitive &&
351+
echo "secret" >sensitive/file &&
352+
353+
git init malicious &&
354+
rm -fr malicious/.git/objects &&
355+
ln -s "$(pwd)/sensitive" ./malicious/.git/objects &&
356+
357+
test_must_fail git clone --local malicious clone 2>err &&
358+
359+
test_path_is_missing clone &&
360+
grep "failed to start iterator over" err
361+
'
362+
347363
test_done
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
3+
test_description='test local clone with ambiguous transport'
4+
5+
. ./test-lib.sh
6+
. "$TEST_DIRECTORY/lib-httpd.sh"
7+
8+
if ! test_have_prereq SYMLINKS
9+
then
10+
skip_all='skipping test, symlink support unavailable'
11+
test_done
12+
fi
13+
14+
start_httpd
15+
16+
REPO="$HTTPD_DOCUMENT_ROOT_PATH/sub.git"
17+
URI="$HTTPD_URL/dumb/sub.git"
18+
19+
test_expect_success 'setup' '
20+
mkdir -p sensitive &&
21+
echo "secret" >sensitive/secret &&
22+
23+
git init --bare "$REPO" &&
24+
test_commit_bulk -C "$REPO" --ref=main 1 &&
25+
26+
git -C "$REPO" update-ref HEAD main &&
27+
git -C "$REPO" update-server-info &&
28+
29+
git init malicious &&
30+
(
31+
cd malicious &&
32+
33+
git submodule add "$URI" &&
34+
35+
mkdir -p repo/refs &&
36+
touch repo/refs/.gitkeep &&
37+
printf "ref: refs/heads/a" >repo/HEAD &&
38+
ln -s "$(cd .. && pwd)/sensitive" repo/objects &&
39+
40+
mkdir -p "$HTTPD_URL/dumb" &&
41+
ln -s "../../../.git/modules/sub/../../../repo/" "$URI" &&
42+
43+
git add . &&
44+
git commit -m "initial commit"
45+
) &&
46+
47+
# Delete all of the references in our malicious submodule to
48+
# avoid the client attempting to checkout any objects (which
49+
# will be missing, and thus will cause the clone to fail before
50+
# we can trigger the exploit).
51+
git -C "$REPO" for-each-ref --format="delete %(refname)" >in &&
52+
git -C "$REPO" update-ref --stdin <in &&
53+
git -C "$REPO" update-server-info
54+
'
55+
56+
test_expect_success 'ambiguous transport does not lead to arbitrary file-inclusion' '
57+
git clone malicious clone &&
58+
test_must_fail git -C clone submodule update --init 2>err &&
59+
60+
test_path_is_missing clone/.git/modules/sub/objects/secret &&
61+
# We would actually expect "transport .file. not allowed" here,
62+
# but due to quirks of the URL detection in Git, we mis-parse
63+
# the absolute path as a bogus URL and die before that step.
64+
#
65+
# This works for now, and if we ever fix the URL detection, it
66+
# is OK to change this to detect the transport error.
67+
grep "protocol .* is not supported" err
68+
'
69+
70+
test_done

0 commit comments

Comments
 (0)